一、什么是Schema约束
Schema,也被称为XML Schema Definition(XSD),描述XML文档的结构,是基于XML的DTD替代者,比DTD更强大。
二、Schema的优势
Schema的优势:Schema可针对未来的需求进行扩展,是基于xml编写,支持数据类型,更完善,功能更强大。
通过可扩展的Schema定义,可以:在其他Schema中重复使用您的Schema,创建由标准类型衍生而来的自己的数据类型,在相同的文档中引用多重的Schema。
三、Schema的实际应用:
使用Schema的xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<email xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="email.xsd">
<to>liuwei8809@163.com</to>
<from>hellokity@163.com</from>
<title>about loving</title>
<body>I love you</body>
<date>2008-11-12</date>
</email>
相应的Schema文件:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="email">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"></xs:element>
<xs:element name="from" type="xs:string"></xs:element>
<xs:element name="title" type="xs:string"></xs:element>
<xs:element name="body" type="xs:string"></xs:element>
<xs:element name="date" type="xs:date"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</schema>
四、总结:
本文主要总结了什么是Schema,Schema为什么会替代DTD,必然有它自身的优势所在。然后实际给出了一个使用Schema约束的小例子。 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|