在前面的xml模式文档(xml:Schema)详解博文中讲解了大量xml和schema的知识,量比较大,可能有点晕。现在来做点小实验来验证下这些知识。
首先note.xsd文件
- <?xml version="1.0"?>
- <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- targetNamespace="http://www.w3schools.com"
- xmlns="http://www.w3schools.com"
- elementFormDefault="qualified">
- <xsd:element name="note">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="to" type="xsd:string"/>
- <xsd:element name="from" type="xsd:string"/>
- <xsd:element name="heading" type="xsd:string"/>
- <xsd:element name="body" type="xsd:string"/>
- </xsd:sequence>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
- <?xml version="1.0"?>
- <note xmlns="http://www.w3schools.com"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.w3schools.com note.xsd">
- <to>Tove</to>
- <from>Jani</from>
- <heading>Reminder</heading>
- <body>Don't forget me this weekend!