XML Schema

xml文件的基本实例:
<?xml version="1.0" encoding="utf-8" ?>
<notes xmlns="http://www.robchen.cn/news" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.robchen.cn/news newsSchema.xsd">
<note>
<title>HTML</title>
<summary>Learning HTML</summary>
<author>
<name>Susan Smith</name>
<sex>female</sex>
</author>
<tags>HTML CSS</tags>
<hit date="2007-11-17">267</hit>
<url>http://www.robchen.cn/news/HTML.html</url>
</note>
<note postDate="2007-11-17">
<title>Ajax</title>
<summary>Learning Ajax</summary>
<author>
<sex>male</sex>
<name>Robin Chen</name>
<age>22</age>
</author>
<tags>Ajax JavaScript XML JSON</tags>
<hit date="2007-11-17">854</hit>
<url>http://www.robchen.cn/news/JSON.html</url>
</note>
<note>
<title>XML Schema</title>
<summary>Something About the XML Schema</summary>
<comment>Nice</comment>
<author>
<name>Robin Chen</name>
<age>22</age>
</author>
<url>http://www.robchen.cn/news/XMLSchema.htm</url>
</note>
</notes>


对应的xsd文件,也就是newsSchema.xsd文件:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1" targetNamespace="http://www.robchen.cn/news" elementFormDefault="qualified" xmlns="http://www.robchen.cn/news" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="notes" type="Notes">
</xs:element>
<xs:element name="comment" type="xs:string">
</xs:element>
<xs:complexType name="Notes">
<xs:sequence>
<xs:element name="note" type="Note" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Note">
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="summary" type="xs:string" />
<xs:element ref="comment" minOccurs="0" />
<xs:element name="author" type="AuthorType" maxOccurs="unbounded" />
<xs:element name="tags" type="TagsType" minOccurs="0" />
<xs:element name="hit" type="HitType" default="0" minOccurs="0" />
<xs:element name="url" type="UrlType" />
</xs:sequence>
<xs:attribute name="postDate" default="2007-11-17" type="xs:date" />
</xs:complexType>
<xs:complexType name="AuthorType">
<xs:all>
<xs:element name="name" type="xs:string" minOccurs="1" />
<xs:element name="sex" type="SexType" minOccurs="0" />
<xs:element name="age" type="AgeType" minOccurs="0" />
</xs:all>
</xs:complexType>
<xs:simpleType name="SexType">
<xs:restriction base="xs:string">
<xs:enumeration value="male" />
<xs:enumeration value="female" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="AgeType">
<xs:restriction base="xs:integer">
<xs:maxInclusive value="80" />
<xs:minInclusive value="20" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TagType">
<xs:list itemType="xs:token">
</xs:list>
</xs:simpleType>
<xs:simpleType name="TagsType">
<xs:restriction base="TagType">
<xs:minLength value="0" />
<xs:maxLength value="10" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="HitType">
<xs:simpleContent>
<xs:extension base="xs:nonNegativeInteger">
<xs:attribute name="date" type="xs:date" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="UrlType">
<xs:restriction base="xs:string">
<xs:pattern value="http://www.robchen.cn/news/.*\.(html|htm)"></xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:schema>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值