good things must see!! it's about xml schema.
The W3C XML Schema Definition Language is an XML language for describing and constraining the content of XML documents. W3C XML Schema is a W3C Recommendation.
This article is an introduction to using W3C XML Schemas, and also includes a comprehensive reference to the Schema datatypes and structures.
Introducing our First Schema
Let's start by having a look at this simple document which describes a book:
<?xml version="1.0" encoding="UTF-8"?>
<book isbn="0836217462">
<title>
Being a Dog Is a Full-Time Job
</title>
<author>Charles M. Schulz</author>
<character>
<name>Snoopy</name>
<friend-of>Peppermint Patty</friend-of>
<since>1950-10-04</since>
<qualification>
extroverted beagle
</qualification>
</character>
<character>
<name>Peppermint Patty</name>
<since>1966-08-22</since>
<qualification>bold, brash and tomboyish</qualification(性格之意)>
</character>
</book>
To write a schema for this document, we could simply follow its structure and define each element as we find it. To start, we open a xs:schema element:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
.../...
</xs:schema>
The schema element opens our schema. It can also hold the definition of the target namespace and several default options, of which we will see some of them in the following sections.
To match the start tag for the book element, we define an element named book. This element has attributes and non text children, thus we consider it as a complexType (since the other datatype, simpleType is reserved(保留) for datatypes holding only values and no element or attribute sub-nodes. The list of children of the book element is described by a sequence element:
<xs:element name="book">
<xs:complexType>
<xs:sequence>
.../...
</xs:sequence>
.../...
</xs:complexType>
</xs:element>
The sequence is a "compositor(排序)" that defines an ordered sequence of sub-elements. We will see the two other compositors(排序), choice and all in the following sections.
Now we can define the title and author elements as simple types -- they don't have attributes or non-text children and can be described directly within a degenerate(退化) element element. The type (xs:string) is prefixed by the namespace prefix associated with XML Schema, indicating a predefined XML Schema datatype:
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
Now, we must deal with the character element, a complex type. Note how its cardinality(集的势,基数) is defined:
<xs:element name="character" minOccurs="0" maxOccurs="unbounded(无限大)">
<xs:complexType>
<xs:sequence>
.../...
</xs:sequence>
</xs:complexType>
</xs:element>
Unlike other schema definition languages, W3C XML Schema lets us define the cardinality of an element (i.e. the number of its possible occurrences) with some precision. We can specify both minOccurs (the minimum number of occurences) and maxOccurs (the maximum number of occurrences). Here maxOccurs is set to unbounded which means that there can be as many occurences of the character element as the author wishes. Both attributes have a default value of one.
We specify then the list of all its children in the same way:
<xs:element name="name" type="xs:string"/>
<xs:element name="friend-of" type="xs:string"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="since" type="xs:date"/>
<xs:element name="qualification" type="xs:string"/>
And we terminate(终结) its description by closing the complexType , element and sequence elements.
We can now declare the attributes of the document elements, which must always come last. There appears to be no special reason for this, but the W3C XML Schema Working Group has considered that it was simpler to impose a relative order to the definitions of the list of elements and attributes within a complex type, and that it was more natural to define the attributes after the elements.
<xs:attribute name="isbn" type="xs:string"/>
And close all the remaining elements.
That's it! This first design, sometimes known as "Russian Doll Design" tightly follows the structure of our example document.
One of the key features of such a design is to define each element and attribute within its context and to allow multiple occurrences of a same element name to carry different definitions.
Complete listing of this first example:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="character" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="friend-of" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="since" type="xs:date"/>
<xs:element name="qualification" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
相关推荐
数据结构之图的广度优先搜索
遍历原则: 从图中指定的
广度优先搜索的c语言实现
今天下午有时间,好奇图论,所以把算法导论的22章的图论的基础给看了一下,最后那个强连通分量我没看,不知道有什么用处,等到要用的时候再看吧,一切按照兴趣走。晚上花了两个多小时把广度优先搜索的部分给实现了一遍,感觉还是比较棒的。整个过程中的数据结构方面,我没有因为实现方面的原因而浪费空间,尽力实现了这个广度优先搜索。 直接上附上代码,以后直接在代码上注释吧,不过多地写废话了,一些概念都在书上
crazyswarm无人机集群搭建笔记(一)资料索引
crazyswarm无人机搭建笔记:资料收集
Ansys-结构动力学分析-圆柱斜齿轮模态分析学习心得
模态分析的步骤基本一直,不同点在于选择什么单元类型,模型,节点约束等 圆柱斜齿轮模态分析的难点在于圆柱斜齿轮的模型建立,和所要约束的节点的选择。 用命令流方法建立齿轮模型效率较高,当然,在ansys里建立复杂的模型实在不敢恭维,对于自下而上建模,需要知道每个关键点的坐标位置。下图是创建圆柱斜齿轮模型的命令流方式。 模型不同使用的数据也就不同了。 对于施加约束的问题这就必须要熟悉select e...
NX/UG二次开发—CAM—设置程序修剪边界Boundary
最近做了一个设置CAM程序边界的小工具,分享一下经验(官方的代码在文章末尾处),以下均以修剪边界曲线为例。 以下为官方提供的源码: /***************************** Include Files **********************************/ #include <stdlib.h> #include <uf.h> #include <uf_obj.h> #include <uf_object_type


