xml,dtd,xsd演进的简单介绍

XML

XML被设计用来传输和存储数据的。
XML标签没有被预定义。需要自行定义标签
示例:note.xml
< ?xml version=“1.0”?>
< note>
< to>George< /to>
< from>John< /from>
< heading>Reminder< /heading>
< body>Don’t forget the meeting!< /body>
< /note>

DTD

可定义合法的XML文档构建模块:节点的提前声明,每一个XML文件均可携带一个有关其自身格式的描述
示例:note.dtd

<!ELEMENT note (to, from, heading, body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>

第 1 行定义 note 元素有四个子元素:“to, from, heading, body”。
第 2-5 行定义了 to, from, heading, body 元素的类型是 “#PCDATA”。
对dtd文件的引用:< !DOCTYPE note SYSTEM “http://www.w3school.com.cn/dtd/note.dtd”>

XSD

XML Schema是DTD替代者。XML Schema 语言也称作XML Schema定义(XSD)
示例:note.xsd
< ?xml version=“1.0”?>
< xs:schema xmlns:xs=“http://www.w3.org/2001/XMLSchema
targetNamespace=“http://www.w3school.com.cn
xmlns=“http://www.w3school.com.cn
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>
< /xs:schema>
解释:xmlns属性可以在文档中定义一个或多个可供选择的命名空间。该属性可以放置在文档内任何元素的开始标签。定义了一个命名空间,浏览器会将此命名空间用于该属性所在元素内所有内容。
xmlns:xs就规定了来自命名空间"http://www.w3.org/2001/XMLSchema" 的元素和数据类型应该使用前缀 xs:

对xsd的引用:

<?xml version="1.0"?>

< note
xmlns=“http://www.w3school.com.cn
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation=“http://www.w3school.com.cn note.xsd”>
解释:有了xmln:xsi这个实例命名空间,则就可以使用schemaLocation属性。

语法:
< schema>元素是每一个XML Schema的根元素

猜你喜欢

转载自blog.csdn.net/xi15232131135/article/details/86489608