XML Schema and XMLspy notes
Introduction
An xml documents consists of elements, attributes and text.
There are two structures in an xml document:
simple ( contains only text ) can ba either Built-in, or Derived
complex ( has attributes or child elements, and possibly texts as well)
Restriction on values:
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>
</xs:restriction> </xs:simpleType>
</xs:element>
To limited the content of an XML element to a set of acceptable values, we can use the enumeration constraint:
<xs:element name="car" type="carType"/>
<xs:simpleType name="carType">
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
Restrictions on a Series of Values
<xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z][A-Z][A-Z]"/>
<xs:pattern value="[a-zA-Z0-9]{8}"/>
<xs:length value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
xs:schema is the root element of the XSD document
<xs: schame
xmlns:xs="http://www.w3.org/2001/XMLSchema" //must have the namespace declaration (Schema for schemas i.e. "http://www.w3.org/2001/XMLSchema")
version="1.1">
...
...
</xs:schema> under xs:schema (global:can be referenced)/further down the schema hierarchy (local)
global elements also can be substituted by another element!
xs:schema cam contain the following child elements:
- xs:include
- xs:import
- xs:override new to XML Schema 1.1
- xs:element
- xs:attribute
- xs:group enables you to specidy constraints on a specific set of sub-elements
- xs:attributeGroup
- xs:annotation can contain two child elements: xs:appinfo/xs:documentation
- xs:defaultOpenContent new to XML Schema 1.1
- xs:simpleType or
- xs:complexType re-use previous definitions (base="complexTypeName", type="complexTypeName")
i.e.
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2014(x64) (http://www.altova.com) by Christian Luntzer (Altova GmbH) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.1">
<xs:element name="city" type="xs:string" default="MainStreet"/>
//global element name is mandatory, type is optional
<xs:element name="shoesize"> //Complex Element type1: simple contents
<xs:complexType> //Only contains simple contents: text, attributes
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="country" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="address">
<xs:complexType> //Complex element Type2: mixed contents
<xs:annotation>
<xs:documentation>type which contains driver....
</xs:documentation>
</xs:annotation>
<xs:sequence mixed="ture"> //contains mixed contents
<xs:element name="street" type="xs:string"/> //local element declaration "street", mandatory
<xs:element ref="city"/>//local element reference"city", name and type attribute cannot be present </xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="product"> //Complex element Type3: only attribute content
<xs:complexType>
<xs:complexContent>
<xs:restriction base="xs:integer“>
<xs:attribute name="prodid" type="xs:positiveInteger"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
Attributes only can be simple, not complex
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2014(x64) (http://www.altova.com) by Christian Luntzer (Altova GmbH) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.1">
<xs:element name="gift_voucher">
<xs:complexType>
<xs:attribute ref="voucher_id"/> //local attribute reference to a global attribute declaration
<xs:attribute name="expiry_date" type="xs:date"/> //(local attribute) name is mandatory, type is optional </xs:complexType>
</xs:element>
<xs:attribute name="voucher_id" type="xs:positiveInteger"/> global attribute declaration
<xs:element name="person"> //MinOccurs and MaxOccurs can be used for both element and group
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string" maxOccurs="10" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
default/fixed: mutually exclusive
If an element appeas but is empty, the schema processor provides the default value. If the element is missing, the schema processor does not provide the default value.
Cannot appear on local element references.
Attribute's default value will provide a default value for an attribute if the attribute is missing from the xml document. It will not provide a default value for a missing element.
Group must be defined globally, though the local reference to a globally named group can exist.
unnamed groups (compositors): xs:sequence; xs:choice; xs:all also can be used foe complex element
<xs:group name="vehiclegroup" minOccurs="1" maxOccurs="1">
<xs:choice> //only one sub-element can be used from a list of sub-elements
<xs:element name="car"/>
<xs:element name="motorbike"/>
</xs:choice>
</xs:group>
<xs:element name="car" type="carinfo"/>
<xs:complexType name="carinfo">
<xs:sequence>
<xs:group ref="vehiclegroup"/> //re-using a group definition , the referenced element has to be a global one.
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
attributeGroup situations arise where there are several different elements that will require the same set of attributes.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.1">
<xs:element name="person">
<xs:complexType>
<xs:attributeGroup ref="dimensions"/>
</xs:complexType>
</xs:element>
<xs:attributeGroup name="dimensions">
<xs:attribute name="height" type="xs:positiveInteger"/>
<xs:attribute name="weight" type="xs:positiveInteger"/>
</xs:attributeGroup>
</xs:schema>
Built-in datatypes
only one complex datatype:
<xs: element name="para" type="xs:anyType"/> ==<xs:element name="pare"/>
User-defined Simple Types
simple types can only be derived via restriction. This mean that the derived simple type will only allow a base type it is being derived from. The base type is more general, the derived type is more specific.
Namespaces
Mixing Several Namespaces
<gs:dish xmlns: gs = “http://china.com“
xmlns: uom = “http://units.com“>
<gs:dm uom:unit = “cm“>20</gs:dm>
<gs:vol uom:unit = “1“>5</gs:vol>
<gs:decor>Meissner</gs:decor>
<comment>This is an unqualified element name</comment>
</gs:dish>
reference:
- http://altova-aot.s3.amazonaws.com/Altova%20XML%20Schema%201.120Technology/player.html
- http://www.w3schools.com/schema/
XML Schema and XMLspy notes的更多相关文章
- XML Schema使用技巧——unique
XML Schema使用技巧——unique XML Scheam允许指定某个元素或属性的值在一定得范围内是唯一的.为了指定元素或属性值的唯一性,可以使用<xs:unqiue>元素,使 ...
- XML&DTD&XML Schema学习
XML(eXtensible Markup Language)可扩展的标记语言.xml在web service编程中尤为重要.在网络传输中可以作为传输数据的载体.xml作为元语言,它可以用来标记数据. ...
- XSD(XML Schema Definition)用法实例介绍以及C#使用xsd文件验证XML格式
XML Schema 语言也称作 XML Schema 定义(XML Schema Definition,XSD),作用是定义 XML 文档的合法构建模块,类似 DTD,但更加强大. 作用有: ①定义 ...
- XML Schema命名空间解析
URI Web中汇集了各种资源.资源可以是具有标识的任何事物, 如文档. 文件. 菜单项. 计算机. 服务等, 甚至可以包括人. 组织和概念[BernersLee 1998].在Web体系结构中, ...
- 【转】XSD (xml Schema Definition)
来自:http://www.cnblogs.com/newsouls/archive/2011/10/28/2227765.html Xml Schema的用途 1. 定义一个Xml文档中都有什么元 ...
- C#与XML Schema的问题
http://bbs.csdn.net/topics/50493564 weileily: 用XmlSchema.Read方法读取了一个xsd文件,请问如何遍历检索器中的ComplexType与Sim ...
- XML Schema的基本语法(转)
XML Schema的基本语法(转) XSDL(XML Schema定义语言)由元素.属性.命名空间和XML文档种的其他节点构成的. 一.XSD中的元素 XSD文档至少要包含:schema根元素和XM ...
- Xml Schema:C#访问在complextype中插入新元素
最近用c#写Xml Schema代码,找了很久也找不到如何在已有的complextype中插入新的element,最后我充分发挥自己的聪明才智,哈哈,终于从...中找到了灵感. XmlSchemaSe ...
- [BTS] System.Xml.Schema.XmlSchemaException: The complexType has already been declared when generate IDoc schema.
I use wcf-sap adapter for generate the schema of IDoc that named "YHREMPMASTER". but throw ...
随机推荐
- cookie实现记住密码
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- AngularJS笔记---路由视图
最近有同事提到过关于ng-view的使用, 其实自己也不懂了,由于最近一直在做AngularJs的Rearch,所以就看了一些关于ng-view的国外博客. 做过ASP.NET MVC4的都知道, 我 ...
- POJ1275 Cashier Employment[差分约束系统 || 单纯形法]
Cashier Employment Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7997 Accepted: 305 ...
- 洛谷P1220关路灯[区间DP]
题目描述 某一村庄在一条路线上安装了n盏路灯,每盏灯的功率有大有小(即同一段时间内消耗的电量有多有少).老张就住在这条路中间某一路灯旁,他有一项工作就是每天早上天亮时一盏一盏地关掉这些路灯. 为了给村 ...
- AJAX提交方法(GET)Demon
AJAX作为一种异步的Javascript程序执行方法,极大的弥补了HTTP协议的不足(HTTP协议为无状态协议),可以无需加载整个页面,只需加载所需数据即可,浏览器内置的XMLHttp对象有open ...
- Struts2 easy UI插件
一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...
- P1546 最短网络 Agri-Net
题目背景 农民约翰被选为他们镇的镇长!他其中一个竞选承诺就是在镇上建立起互联网,并连接到所有的农场.当然,他需要你的帮助. 题目描述 约翰已经给他的农场安排了一条高速的网络线路,他想把这条线路共享给其 ...
- Android5.0资源 colorAccent,colorPrimary,colorPrimaryDark
- C#基础系列——小话泛型
前言:前面两章介绍了C#的两个常用技术:C#基础系列——反射笔记 和 C#基础系列——Attribute特性使用 .这一章来总结下C#泛型技术的使用.据博主的使用经历,觉得泛型也是为了重用而生的,并且 ...
- hibernate通过xml配置文件实现表与实体的映射
这里讨论的是一对多的关系 在做公交卡系统,会涉及到两张表,忽略两种表的作用,只关心他们之间的关系 : 卡规格表和卡类表,一种卡规格会对应多个卡类 实体类: /** * 卡类型表的实体 */ publi ...