XML 简介 (from W3C School)

来源:互联网 发布:中科院对学生调查数据 编辑:程序博客网 时间:2024/05/22 16:01

XML Overiew:

XML 指可扩展标记语言

XML 被设计用来传输和存储数据。

XML 的设计宗旨是传输数据,而非显示数据

XML 标签没有被预定义。您需要自行定义标签

XML 被设计为传输和存储数据,其焦点是数据的内容。

HTML 被设计用来显示数据,其焦点是数据的外观。

HTML 旨在显示信息,而 XML 旨在传输信息。

XML 应用于 web 开发的许多方面,常用于简化数据的存储和共享。

<bookstore><book category="CHILDREN">  <title>Harry Potter</title>   <author>J K. Rowling</author>   <year>2005</year>   <price>29.99</price> </book><book category="WEB">  <title>Learning XML</title>   <author>Erik T. Ray</author>   <year>2003</year>   <price>39.95</price> </book></bookstore> 

在上例中,<bookstore> 和 <book> 都拥有元素内容,因为它们包含了其他元素。<author> 只有文本内容,因为它仅包含文本。在上例中,只有 <book> 元素拥有属性 (category="CHILDREN")。

<person sex="female">  <firstname>Anna</firstname>  <lastname>Smith</lastname></person> <person>  <sex>female</sex>  <firstname>Anna</firstname>  <lastname>Smith</lastname></person> 
在第一个例子中,sex 是一个属性。在第二个例子中,sex 则是一个子元素。两个例子均可提供相同的信息。


XML Schema

XML Schema 描述 XML 文档的结构。

XML Schema 语言也称作 XML Schema 定义(XML Schema Definition,XSD)。

请看这个名为 "note.xml" 的 XML 文档:

<?xml version="1.0"?><note><to>George</to><from>John</from><heading>Reminder</heading><body>Don't forget the meeting!</body></note>
下面这个例子是一个名为 "note.xsd" 的 XML Schema 文件,它定义了上面那个 XML 文档的元素:

<?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>

此文件包含对 XML Schema 的引用:

<?xml version="1.0"?><notexmlns="http://www.w3school.com.cn"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.w3school.com.cn note.xsd"><to>George</to><from>John</from><heading>Reminder</heading><body>Don't forget the meeting!</body></note>






0 0