XML中的几个名词

  • DTD

document type definition

引入外部dtd文件的方式:

  1. <!DOCTYPE 根元素名称 SYSTEM "DTD文件path">
  2. <!DOCTYPE 根元素名称 PUBLIC "DTD文件名称" "DTD文件uri">(引入网络上的dtd文件)
  • XSD

xml schema definition

<!--xml文档声明-->

<?xml version="1.0"?>

<!--该schema中用到的元素和数据类型都来自http://www.w3.org/2001/XMLSchema命名空间,同时因为xmlns:命名空间前缀,所以该schema的元素都需要加前缀xs-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

<!--被该schema定义的元素来自http://www.w3schools.com命名空间-->
targetNamespace="http://www.w3schools.com"

<!--http://www.w3schools.com是默认的命名空间-->
xmlns="http://www.w3schools.com"

<!--xml文档使用的在此schema中声明过的元素都应该被命名空间限定-->
elementFormDefault="qualified">

<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
      <xs:element name="from" type="xs:string"/>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="body" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

 

<beans xmlns="http://www.springframework.org/schema/beans"
<!--有此xml schema实例命名空间才可以使用xsi:scheamLocation属性引用xsd文件校验xml文件格式-->
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
<!--schemaLocation有是由"key1 value1 key2 value2..."组成,其中key是命名空间uri,对应的value是要校验该命名空间元素的格式的xsd文件的path,通常也是一个uri-->
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
  • CDATA

character data:(未解析)字符数据,即不应该被xml解析器解析的字符数据,和PDATA结合理解

<![CDATA[不希望(不会)被解析的字符串]]>

  • PCDATA

parsed CDATA:被解析的字符数据

  • XML命名空间
  1. 定义在开始标签的xmlns属性<element xmlns="namespaceURI"></element>
  2. 定义在根元素的开始标签<root xmlns="namespaceURI"></root>

所有带有相同前缀的子元素都会和同一命名空间相关联

xmlns:命名空间=uri

默认的命名空间:xmlns=uri

使用默认的命名空间,子元素可以省去加前缀的麻烦

例:spring的默认命名空间:

xmlns="http://www.springframework.org/schema/beans"
  • 实体引用

xml中有5个预定义的实体引用

  1. &lt;(小于号<)
  2. &gt;(大于号>)
  3. &amp;(与字符&)
  4. &quot;(双引号)
  5. apos;(单引号)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值