一个完整的schema验证xml的例子
2015-07-22 21:29
441 查看
xml文件:
<reference xmlns="http://www.w3school.com.cn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3school.com.cn J.xsd"> <author authorLoc="1">陈路瑶</author> <title>信息文档结构信任模式的提取及逻辑描述</title> <type>J</type> <publisher>计算机应用研究</publisher> <publish_year>2010</publish_year> <volumn_mark>27</volumn_mark> <page_number>4624-4629</page_number> </reference>
schema文件(J.xsd):
<?xml version="1.0" encoding="GB2312"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3school.com.cn" targetNamespace="http://www.w3school.com.cn" elementFormDefault="qualified">
<xs:element name="reference">
<xs:complexType>
<xs:sequence>
<xs:element name="author" type="authorInfo" minOccurs="1" maxOccurs="1"/>
<xs:element name="title" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="type" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="publish" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="publisher" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="publish_year" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="volumn_mark" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="page_number" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(\d{1,4}-)?\d{1,4}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="authorInfo">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="authorLoc" use="required">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:enumeration value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
相关文章推荐
- XML 与 JSON 优劣对比
- As3.0 xml + Loader应用代码
- 网马生成器 MS Internet Explorer XML Parsing Buffer Overflow Exploit (vista) 0day
- ext读取两种结构的xml的代码
- PostgreSQL教程(二):模式Schema详解
- C#针对xml基本操作及保存配置文件应用实例
- asp下查询xml的实现代码
- sqlserver FOR XML PATH 语句的应用
- 使用sp_xml_preparedocument处理XML文档的方法
- C#中的Linq to Xml详解
- C#操作XML文件实例汇总
- SQL Server中的XML数据进行insert、update、delete
- SQL Server中的XML数据进行insert、update、delete操作实现代码
- 关于SQLServer2005的学习笔记 XML的处理
- C#通过DataSet读写xml文件的方法
- php xml 入门学习资料
- Zend 输出产生XML解析错误
- PHP遍历XML文档所有节点的方法
- php的XML文件解释类应用实例