当前位置: 首页 > 网络学院 > XML相关教程 > Schema (XSD) > 如何定制 XSD

Schema (XSD)
XSD 逻辑值数据类型
XML Schema总结
XML Schema 参考
XSD 验证

Schema (XSD) 中的 如何定制 XSD


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 839 ::
收藏到网摘: n/a

XML documents can have a reference to a DTD or to an XML Schema.
XML文档可以与一份DTD或XML Schema相关联。


A Simple XML Document
一份简单的XML文档

Look at this simple XML document called "note.xml":
请看下面一份名为"note.xml"的简易XML文档:

<?xml version="1.0"?>
<note>

<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

 


A DTD File
一份DTD文件

The following example is a DTD file called "note.dtd" that defines the elements of the XML document above ("note.xml"):
下述案例列举了名为"note.dtd"的DTD文件,它定义了上述XML文档("note.xml")中的元素:

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

The first line defines the note element to have four child elements: "to, from, heading, body".
第一行定义了包含“to、from、heading、body”四个子元素的“note”元素。

Line 2-5 defines the to, from, heading, body elements to be of type "#PCDATA".
第2到5行定义了"#PCDATA"类型的“to、from、heading、body”四个元素。


An XML Schema
一份XML Schema

The following example is an XML Schema file called "note.xsd" that defines the elements of the XML document above ("note.xml"):
下述案例中,一个名为"note.xsd"的XML Schema文件定义了上述XML文档("note.xml")中的元素:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"

xmlns="http://www.w3schools.com"
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>

The note element is a complex type because it contains other elements. The other elements (to, from, heading, body) are simple types because they do not contain other elements. You will learn more about simple and complex types in the following chapters.
Note元素是复合类型(complex type)因为它包含了其它元素;其它元素(to、rom、heading、 body)属于简单类型(simple type),因为它不包含其它元素。在下面的几章中,你会学习更多关于简单类型和复合类型的相关知识。


A Reference to a DTD
与DTD相关

This XML document has a reference to a DTD:
下述这份XML文档与DTD相关:

<?xml version="1.0"?>
<!DOCTYPE note SYSTEM
"http://www.w3schools.com/dtd/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>

<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

 


A Reference to an XML Schema
与XML Schema相关

This XML document has a reference to an XML Schema:
下述这份XML文档与XML 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!</body>

</note>

评论 (0) All

登陆 | 还没注册?