+ -
当前位置:首页 → 问答吧 → 一个xml引入了约束的自己编写的schema (xsd)文件后?

一个xml引入了约束的自己编写的schema (xsd)文件后?

时间:2011-04-01

来源:互联网

一个xml引入了约束的自己编写的schema (xsd)文件,怎样简单验证是不是合法?xml本身是不是不能在扩展其它元素了?

作者: pmrc2009   发布时间: 2011-04-01

xsd文件中的规则约束:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.cnblogs.com/tankaixiong"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="bookstore">
  <xs:complexType>
  <xs:sequence>
  <xs:element maxOccurs="unbounded" name="book">
  <xs:complexType>
  <xs:sequence>
  <xs:element name="title" type="xs:string" />
  <xs:element name="author">
  <xs:complexType>
  <xs:sequence>
  <xs:element minOccurs="0" name="name" type="xs:string" />
  <xs:element minOccurs="0" name="first-name" type="xs:string" />
  <xs:element minOccurs="0" name="last-name" type="xs:string" />
  </xs:sequence>
  </xs:complexType>
  </xs:element>
  </xs:sequence>
  </xs:complexType>
  </xs:element>
</xs:schema>

XML中的引用
<bookstore xmlns="http://www.cnblogs.com/tankaixiong">
  <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
  <title>The Autobiography of Benjamin Franklin</title>
  <author>
  <first-name>Benjamin</first-name>
  <last-name>Franklin</last-name>
  </author>
  </book>
</bookstore>

作者: tankaixiong   发布时间: 2011-04-02

热门下载

更多