约束文件 。xsd
代码:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="book" type="booktype"></xs:element>
<xs:complexType name="booktype" >
<xs:sequence>
<xs:element name="bookName" type="xs:string"></xs:element>
<xs:element name="bookPrice" type="xs:float"></xs:element>
<xs:element name="author" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
complexType是复杂的类型 用来修饰元素,以及增添子元素 或者约束子元素
将约束带人xml中具体,对具体的XML文件约束
XML代码:
<?xml version="1.0" encoding="UTF-8"?>
<book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Untitled3.xsd">
<bookName>倚天屠龙记</bookName>
<bookPrice>23.0</bookPrice>
<author>金庸</author>
</book>