tom
18
male
- dtd约束文档的缺点
-
不能限定内容
-
语法结构:
DTD的语法与XMl不同,使用DOM,XPath,XSL无法处理,为自动化文档处理带来不便
- 数据类型
DTD数据类型不能自由扩充,不利于XML数据交换场合验证
3.文档结构
DTD中,所有元素、属性都是全局的, 无法声明仅与上下文位置相关的元素或属性
- 名称空间
DTD中没有名称空间的概念,不直接支持名称空间
2、Schema约束文档【主流】
-
Schema:
-
引入:
1.填写xml文档的根元素
2.引入xsi前缀. xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
3.引入xsd文件命名空间. xsi:schemaLocation=“http://www.itcast.cn/xml student.xsd”
4.为每一个xsd约束声明一个前缀,作为标识 xmlns=“http://www.itcast.cn/xml”
<students xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns=“http://www.itcast.cn/xml”
xsi:schemaLocation=“http://www.itcast.cn/xml student.xsd”>
- student.xsd
<xsd:schema xmlns=“http://www.itcast.cn/xml”
xmlns:xsd=“http://www.w3.org/2001/XMLSchema”
targetNamespace=“http://www.itcast.cn/xml” elementFormDefault=“qualified”>
<xsd:element name=“students” type=“studentsType”/>
<xsd:complexType name=“studentsType”>
xsd:sequence
<xsd:element name=“student” type=“studentType” minOccurs=“0” maxOccurs=“unbounded”/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name=“studentType”>
xsd:sequence
<xsd:element name=“name” type=“xsd:string”/>
<xsd:element name=“age” type=“ageType” />
<xsd:element name=“sex” type=“sexType” />
</xsd:sequence>
<xsd:attribute name=“number” type=“numberType” use=“required”/>
</xsd:complexType>
<xsd:simpleType name=“sexType”>
<xsd:restriction base=“xsd:string”>
<xsd:enumeration value=“male”/>
<xsd:enumeration value=“female”/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name=“ageType”>
<xsd:restriction base=“xsd:integer”>
<xsd:minInclusive value=“0”/>
<xsd:maxInclusive value=“256”/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name=“numberType”>
<xsd:restriction base=“xsd:string”>
<xsd:pattern value=“heima_\d{4}”/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
- xml导入写框架人写的约束
<students xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns=“http://www.itcast.cn/xml”
xsi:schemaLocation=“http://www.itcast.cn/xml student.xsd”
tom
18
male
- Springmvc的xml详解
<beans xmlns=“http://www.springframework.org/schema/beans”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns:context=“http://www.springframework.org/schema/context”
xmlns:mvc