初始XML写法
<?xml version="1.0" encoding="UTF-8" ?>
<!-- comment is this format, and it will be displayed by green -->
<College>
<Teacher>
<name> 罗翔 </name>
<gender> Female </gender>
<major> law </major>
<info>
<age> >40 <50 </age>
<career> &18 'K "F </career>
<addr>bilibili</addr>
</info>
</Teacher>
<![CDATA[
1<2 3>2 name=`T` & "Peter"
]]>
</College>
dtd约束文档
<!ELEMENT Bookshelf (Book+)>
<!ELEMENT Book (Name Author Price)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Author (#PCDATA)>
<!ELEMENT Price (#PCDATA)>
dtd约束后的xml文件写法
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE Bookshelf SYSTEM "regular.dtd">
<!-- 我是一个DTD约束的XML文件 -->
<Bookshelf>
<Book>
<Name>Robinson</Name>
<Author>Crusoe</Author>
<Price>99.9</Price>
</Book>
<Book>
<Name>The Whale</Name>
<Author>Moby Dick</Author>
<Price>99.8</Price>
</Book>
</Bookshelf>
可以规定数据类型的schema约束格式
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.notexist.com"
elementFormDefault="qualified">
<!-- targetNamespace 申明约束文档的地址,又叫命名空间 -->
<element name="Bookshelf">
<complexType>
<sequence maxOccurs="unbounded">
<element name="Book">
<complexType>
<sequence>
<element name="name" type="string"/>
<element name="author" type="string"/>
<element name="price" type="double"/>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
约束后的xml写法
<?xml version="1.0" encoding="UTF-8" ?>
<Bookshelf xmlns="http://www.notexist.com">
<Book>
<name>Surveiller et Punir</name>
<author>Foucault</author>
<price>108.0</price>
</Book>
</Bookshelf>