- 浏览: 847569 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
贝塔ZQ:
读取excel文件,插件pageoffice也可以实现。
POI读写Excel文件(转)- - -
springmvc-freemarker:
java开源项目源码实例下载
java开源项目源代码 -
xuning2516:
第一种方法是个死循环啊。。。
Java NIO 拷贝文件(使用compact) -
u012046856:
...
SessionFactory.getCurrentSession与openSession的区别 -
Season_Wang:
赞一个呀,挺实用的
java swing 中的FileDialog
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com" elementFormDefault="qualified"> </xs:schema>
The following fragment:
xmlns:xs="http://www.w3.org/2001/XMLSchema"
indicates that the elements and data types used in the schema come from the "http://www.w3.org/2001/XMLSchema" namespace. It also specifies that the elements and data types that come from the "http://www.w3.org/2001/XMLSchema" namespace should be prefixed with xs:
This fragment:
targetNamespace="http://www.w3schools.com"
indicates that the elements defined by this schema (note, to, from, heading, body.) come from the "http://www.w3schools.com" namespace.
This fragment:
xmlns="http://www.w3schools.com"
indicates that the default namespace is http://www.w3schools.com.
This fragment:
elementFormDefault="qualified"
indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified.
Default and Fixed Values for Simple Elements
<xs:element name="color" type="xs:string" default="red"/>
<xs:element name="color" type="xs:string" fixed="red"/>
XSD Attributes
All attributes are declared as simple types.
If an element has attributes, it is considered to be of a complex type. But the attribute itself is always declared as a simple type.
<xs:attribute name="xxx" type="yyy"/>
Default and Fixed Values for Attributes
<xs:attribute name="lang" type="xs:string" default="EN"/>
<xs:attribute name="lang" type="xs:string" fixed="EN"/>
Optional and Required Attributes
<xs:attribute name="lang" type="xs:string" use="required"/>
XSD Restrictions/Facets
Restrictions are used to define acceptable values for XML elements or attributes. Restrictions on XML elements are called facets.
Restrictions 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>
Restrictions on a Set of Values
<xs:element name="car"><xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Audi"/> <xs:enumeration value="Golf"/> <xs:enumeration value="BMW"/> </xs:restriction> </xs:simpleType></xs:element>
or
<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>
in the aboving , carType can be reused.
Restrictions on a Series of Values
<xs:element name="letter"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[a-z]"/> <xs:pattern value="[A-Z][A-Z][A-Z]"/> <xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/> <xs:pattern value="[xyz]"/> <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/> <xs:pattern value="([a-z][A-Z])+"/> <xs:pattern value="([a-z])*"/> <xs:pattern value="male|female"/> <xs:pattern value="[a-zA-Z0-9]{8}"/> <xs:whiteSpace value="preserve"/> <xs:whiteSpace value="replace"/> <xs:whiteSpace value="collapse"/> <xs:length value="8"/> </xs:restriction> </xs:simpleType></xs:element>
复合类型:
继承使用复合类型。
<xs:element name="employee" type="fullpersoninfo"/><xs:complexType name="personinfo"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType><xs:complexType name="fullpersoninfo"> <xs:complexContent> <xs:extension base="personinfo"> <xs:sequence> <xs:element name="address" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="country" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType>
XSD Complex Types Indicators
We can control HOW elements are to be used in documents with indicators.
Indicators
There are seven indicators:
Order indicators:
- All
- Choice
- Sequence
Occurrence indicators:
- maxOccurs
- minOccurs
Group indicators:
- Group name
- attributeGroup name
All Indicator
The <all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once:
<xs:element name="person"> <xs:complexType> <xs:all> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:all> </xs:complexType> </xs:element>
The <choice> indicator specifies that either one child element or another can occur
<xs:element name="person"> <xs:complexType> <xs:choice> <xs:element name="employee" type="employee"/> <xs:element name="member" type="member"/> </xs:choice> </xs:complexType> </xs:element>
Sequence Indicator
The <sequence> indicator specifies that the child elements must appear in a specific order:
<xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
Occurrence Indicators
Occurrence indicators are used to define how often an element can occur.
Note: For all "Order" and "Group" indicators (any, all, choice, sequence, group name, and group reference) the default value for maxOccurs and minOccurs is 1.
maxOccurs Indicator
The <maxOccurs> indicator specifies the maximum number of times an element can occur:
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string" maxOccurs="10"/>
</xs:sequence>
</xs:complexType>
</xs:element>
minOccurs Indicator
The <minOccurs> indicator specifies the minimum number of times an element can occur:
<xs:element name="person">
<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>
Group Indicators
Group indicators are used to define related sets of elements.
You must define an all, choice, or sequence element inside the group declaration.
After you have defined a group, you can reference it in another definition
<xs:group name="persongroup"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:element name="birthday" type="xs:date"/> </xs:sequence> </xs:group> <xs:element name="person" type="personinfo"/> <xs:complexType name="personinfo"> <xs:sequence> <xs:group ref="persongroup"/> <xs:element name="country" type="xs:string"/> </xs:sequence> </xs:complexType>
Attribute Groups
Attribute groups are defined with the attributeGroup declaration
<xs:attributeGroup name="personattrgroup"> <xs:attribute name="firstname" type="xs:string"/> <xs:attribute name="lastname" type="xs:string"/> <xs:attribute name="birthday" type="xs:date"/> </xs:attributeGroup> <xs:element name="person"> <xs:complexType> <xs:attributeGroup ref="personattrgroup"/> </xs:complexType> </xs:element>
XSD The <any> Element
The <any> element enables us to extend the XML document with elements not specified by the schema!
<xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:any minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element>
the following xml isvalid
<?xml version="1.0" encoding="ISO-8859-1"?><persons xmlns="http://www.microsoft.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:SchemaLocation="http://www.microsoft.com family.xsd
http://www.w3schools.com children.xsd">
<person>
<firstname>Hege</firstname>
<lastname>Refsnes</lastname>
<children>
<childname>Cecilie</childname>
</children>
</person>
<person>
<firstname>Stale</firstname>
<lastname>Refsnes</lastname>
</person>
</persons>
The <any> and <anyAttribute> elements are used to make EXTENSIBLE documents! They allow documents to contain additional elements that are not declared in the main XML schema.
XSD The <anyAttribute> Element
<xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> <xs:anyAttribute/> </xs:complexType> </xs:element>
<persons xmlns="http://www.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:SchemaLocation="http://www.microsoft.com family.xsd http://www.w3schools.com attribute.xsd">
使用两个xsd文件。
XSD Element Substitution
With XML Schemas, one element can substitute another element.
<xs:element name="name" type="xs:string"/> <xs:element name="navn" substitutionGroup="name"/> <xs:complexType name="custinfo"> <xs:sequence> <xs:element ref="name"/> </xs:sequence> </xs:complexType> <xs:element name="customer" type="custinfo"/> <xs:element name="kunde" substitutionGroup="customer"/>
Valid xml can be the following:
<customer> <name>John Smith</name> </customer> <kunde> <navn>John Smith</navn> </kunde>
Divide the Schema Demo
Example XSD File:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element></xs:schema>
Divided XSD Files
<?xml version="1.0" encoding="ISO-8859-1" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- definition of simple elements --> <xs:element name="orderperson" type="xs:string"/> <xs:element name="name" type="xs:string"/> <xs:element name="address" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="country" type="xs:string"/> <xs:element name="title" type="xs:string"/> <xs:element name="note" type="xs:string"/> <xs:element name="quantity" type="xs:positiveInteger"/> <xs:element name="price" type="xs:decimal"/> <!-- definition of attributes --> <xs:attribute name="orderid" type="xs:string"/> <!-- definition of complex elements --> <xs:element name="shipto"> <xs:complexType> <xs:sequence> <xs:element ref="name"/> <xs:element ref="address"/> <xs:element ref="city"/> <xs:element ref="country"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="item"> <xs:complexType> <xs:sequence> <xs:element ref="title"/> <xs:element ref="note" minOccurs="0"/> <xs:element ref="quantity"/> <xs:element ref="price"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="shiporder"> <xs:complexType> <xs:sequence> <xs:element ref="orderperson"/> <xs:element ref="shipto"/> <xs:element ref="item" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute ref="orderid" use="required"/> </xs:complexType> </xs:element> </xs:schema>
Using Named Types
<xs:simpleType name="stringtype"> <xs:restriction base="xs:string"/> </xs:simpleType>
<xs:element name="title" type="stringtype"/> <xs:element name="note" type="stringtype" minOccurs="0"/>
XSD String Data Types
Define:
<xs:element name="customer" type="xs:string"/>
Example:
<customer> John Smith </customer> Note: The XML processor will not modify the value if you use the string data type.
NormalizedString Data Type
Define:
<xs:element name="customer" type="xs:normalizedString"/>
Example:
<customer> John Smith </customer>
Note: In the example above the XML processor will replace the tabs with spaces.
Token Data Type
The token data type is also derived from the String data type.
The token data type also contains characters, but the XML processor will remove line feeds, carriage returns, tabs, leading and trailing spaces, and multiple spaces.
<xs:element name="customer" type="xs:token"/>
String Data Types
Note that all of the data types below derive from the String data type (except for string itself)!
ENTITIES | |
ENTITY | |
ID | A string that represents the ID attribute in XML (only used with schema attributes) |
IDREF | A string that represents the IDREF attribute in XML (only used with schema attributes) |
IDREFS | |
language | A string that contains a valid language id |
Name | A string that contains a valid XML name |
NCName | |
NMTOKEN | A string that represents the NMTOKEN attribute in XML (only used with schema attributes) |
NMTOKENS | |
normalizedString | A string that does not contain line feeds, carriage returns, or tabs |
QName | |
string | A string |
token | A string that does not contain line feeds, carriage returns, tabs, leading or trailing spaces, or multiple spaces |
Restrictions on String Data Types
Restrictions that can be used with String data types:
- enumeration
- length
- maxLength
- minLength
- pattern (NMTOKENS, IDREFS, and ENTITIES cannot use this constraint)
- whiteSpace
Date and Time Data Types
date | Defines a date value |
dateTime | Defines a date and time value |
duration | Defines a time interval |
gDay | Defines a part of a date - the day (DD) |
gMonth | Defines a part of a date - the month (MM) |
gMonthDay | Defines a part of a date - the month and day (MM-DD) |
gYear | Defines a part of a date - the year (YYYY) |
gYearMonth | Defines a part of a date - the year and month (YYYY-MM) |
time | Defines a time value |
Restrictions on Date Data Types
Restrictions that can be used with Date data types:
- enumeration
- maxExclusive
- maxInclusive
- minExclusive
- minInclusive
- pattern
- whiteSpace
Numeric Data Types
Note that all of the data types below derive from the Decimal data type (except for decimal itself)!
byte | A signed 8-bit integer |
decimal | A decimal value |
int | A signed 32-bit integer |
integer | An integer value |
long | A signed 64-bit integer |
negativeInteger | An integer containing only negative values ( .., -2, -1.) |
nonNegativeInteger | An integer containing only non-negative values (0, 1, 2, ..) |
nonPositiveInteger | An integer containing only non-positive values (.., -2, -1, 0) |
positiveInteger | An integer containing only positive values (1, 2, ..) |
short | A signed 16-bit integer |
unsignedLong | An unsigned 64-bit integer |
unsignedInt | An unsigned 32-bit integer |
unsignedShort | An unsigned 16-bit integer |
unsignedByte | An unsigned 8-bit integer |
Restrictions on Numeric Data Types
Restrictions that can be used with Numeric data types:
- enumeration
- fractionDigits
- maxExclusive
- maxInclusive
- minExclusive
- minInclusive
- pattern
- totalDigits
- whiteSpace
XSD Miscellaneous Data Types
Other miscellaneous data types are boolean, base64Binary, hexBinary, float, double, anyURI, QName, and NOTATION.
Miscellaneous Data Types
anyURI | |
base64Binary | |
boolean | |
double | |
float | |
hexBinary | |
NOTATION | |
QName |
Restrictions on Miscellaneous Data Types
Restrictions that can be used with the other data types:
- enumeration (a Boolean data type cannot use this constraint)
- length (a Boolean data type cannot use this constraint)
- maxLength (a Boolean data type cannot use this constraint)
- minLength (a Boolean data type cannot use this constraint)
- pattern
- whiteSpace
XSD Elements
all | Specifies that the child elements can appear in any order. Each child element can occur 0 or 1 time |
annotation | Specifies the top-level element for schema comments |
any | Enables the author to extend the XML document with elements not specified by the schema |
anyAttribute |
Enables the author to extend the XML document with attributes not specified by the schema |
appInfo | Specifies information to be used by the application (must go inside annotation) |
attribute | Defines an attribute |
attributeGroup | Defines an attribute group to be used in complex type definitions |
choice | Allows only one of the elements contained in the <choice> declaration to be present within the containing element |
complexContent | Defines extensions or restrictions on a complex type that contains mixed content or elements only |
complexType | Defines a complex type element |
documentation | Defines text comments in a schema (must go inside annotation) |
element | Defines an element |
extension | Extends an existing simpleType or complexType element |
field | Specifies an XPath expression that specifies the value used to define an identity constraint |
group | Defines a group of elements to be used in complex type definitions |
import | Adds multiple schemas with different target namespace to a document |
include | Adds multiple schemas with the same target namespace to a document |
key | Specifies an attribute or element value as a key (unique, non-nullable, and always present) within the containing element in an instance document |
keyref | Specifies that an attribute or element value correspond to those of the specified key or unique element |
list | Defines a simple type element as a list of values |
notation | Describes the format of non-XML data within an XML document |
redefine | Redefines simple and complex types, groups, and attribute groups from an external schema |
restriction | Defines restrictions on a simpleType, simpleContent, or a complexContent |
schema | Defines the root element of a schema |
selector | Specifies an XPath expression that selects a set of elements for an identity constraint |
sequence | Specifies that the child elements must appear in a sequence. Each child element can occur from 0 to any number of times |
simpleContent | Contains extensions or restrictions on a text-only complex type or on a simple type as content and contains no elements |
simpleType | Defines a simple type and specifies the constraints and information about the values of attributes or text-only elements |
union | Defines a simple type as a collection (union) of values from specified simple data types |
unique | Defines that an element or an attribute value must be unique within the scope |
XSD Restrictions/Facets for Datatypes
enumeration | Defines a list of acceptable values |
fractionDigits | Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero |
length | Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero |
maxExclusive | Specifies the upper bounds for numeric values (the value must be less than this value) |
maxInclusive | Specifies the upper bounds for numeric values (the value must be less than or equal to this value) |
maxLength | Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero |
minExclusive | Specifies the lower bounds for numeric values (the value must be greater than this value) |
minInclusive | Specifies the lower bounds for numeric values (the value must be greater than or equal to this value) |
minLength | Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero |
pattern | Defines the exact sequence of characters that are acceptable |
totalDigits | Specifies the exact number of digits allowed. Must be greater than zero |
whiteSpace | Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled |
相关推荐
XML(Extensible Markup Language)是一种用于标记数据的语言,它允许用户自定义标签来表示数据,因此在各种领域,如Web服务、数据交换、配置文件等都有广泛应用。XML Schema是XML的一种标准化约束机制,用于定义XML...
XML Schema(通常缩写为XSD)是一种用于定义XML文档结构和数据类型的规范。它提供了对XML元素、属性、数据类型的约束和规范,确保XML文档的一致性和有效性。本案例探讨了两种不同的XML Schema设计模式:千层娃娃模式...
xamarin-android-schema-generator是一个Android layout.xml模式生成器。 警告:Android布局xml不太适合XML模式限制。 XML Schema的扩展性不足以接受非标准组件或非标准属性(由于元素/属性通配符的限制),这些非...
这个问题通常是由于缺少对应的XML Schema定义文件导致的,该文件用于验证和解析Dubbo的XML配置。 `dubbo.xsd`是Dubbo的XML配置文件的Schema定义,它包含了所有Dubbo服务、消费者、提供者、协议、注册中心等组件的...
该项目的目的是从xml shema(xsd)中生成JAVA源代码,以访问符合所用shema的xml文件。 我们还提供GUI(图形用户界面),以提供易于使用的工具。
shema基础 熟悉Schema的结构。 2、掌握Schema中的数据类型、命名空间、元素声明、属性声明。
在Spring框架中,schema约束是XML配置文件中的一个重要组成部分,它们定义了如何正确地配置Spring容器中的各种组件,如bean、property、aop等。Spring 4.2.0是该框架的一个版本,引入了一些新的特性和改进,同时也对...
《Star-Shema 数据仓库维度设计权威指南》完全参考手册是一本深入探讨数据仓库构建方法的专著,尤其聚焦于Star-Schema(星型模式)这一关键设计策略。数据仓库是现代企业信息系统的重要组成部分,它为决策支持系统...
个人认为是不错的XML资料,对大家应该有帮助。
"Abderrahmane_Khemis type1 shema"这一主题,主要探讨的是Abderrahmane Khemis针对类型一模糊逻辑系统设计的一种架构模式或方案,其核心在于如何有效地应用模糊逻辑来解决实际问题。 模糊逻辑的核心概念是模糊集合...
在本篇关于“Oracle10G管理方案对象(shema)”的PPT中,主要探讨了如何有效地管理和操作Oracle数据库中的方案对象,以及相关的数据类型、表的创建与修改、约束条件、索引、视图、序列、临时表和数据字典的使用。...
1. **JSON Schema定义**:JSON Schema是一种JSON格式的规范,提供了验证JSON数据的方法,类似于XML Schema对于XML的作用。它包含了一些元数据,如数据类型、约束和默认值,用来限制JSON对象的结构。 2. **数据验证**...
### 基于cnSchema的开放中文知识图谱 #### 知识图谱简介 - **定义**:知识图谱是一种以结构化的形式表示实体及其之间的关系的数据模型,旨在通过图形化的方式展示复杂的实体间联系,进而提升信息检索、推荐系统、...
JSON Schema 规范(中文版) JSON Schema 是一种强大的工具,用于验证 JSON 数据结构。Schema 可以理解为模式或者规则。在学习 JSON Schema 时,需要理解什么是模式, JSON Schema 的基本类型,如何使用 JSON ...
这个项目曾经是Xamarin开发者生成Android资源XML schema的利器,但现在已经被官方认定为“失败的项目”,取而代之的是由atsushieno维护的“Xamarin.Android Schema Generator”。 【描述】:“monodroid-schema-gen...
当创建了一个的同时也创建了一个通的shema,shema与用户是一一对应的关系。shema是数据库对象的逻辑容器。 在创建用户的过程中可以指定的用户属性有: 1、认证方式 2、认证密码 3、默认的永久表空间,临时表空间 4、...
解决eclipse下载不到dobbo.xsd的报错问题,解决方式:preferences-->xml-->xml Catalog-->user Specified Entries--...key type(Shema location)-->key(http://code.alibabatech.com/schema/dubbo/dubbo.xsd)
1、下载xmlbeans-2.3.0.jar。 2、创建配置文件my.xsdconfig。 3、java方法如下: public class Test { public static void main(String[] args) { String[] a = new String[]{ "-out", "D:\\1\\DccXmlBean...
Necta Canto, global vending manuel. errors , shema