To learn XML Schema (1): How do the simplest Schema document written a simplex XML Schema document?
First, we write a simplest XML document.
Hello.xml ------------------ XML Version = "1.0"?>
(A root element: greeting; and this element does not contain attributes, no child elements, the content is a string.)
Hello.xsd ---------- XML Version = "1.0"?>
XML Schema document After the suffix name is .xsd, fully compliant xml syntax, root element is schema, named space XMLns: XSD = "http://www.w3.org/2001/xmlschema, with element
Suppose the instance document is as follows:
Customer.xml -----------
You can write the following XML Schema document: Customer.xsd ---------------- 1:
In the instance document Customer.xml, the
The sequence represents the order in which the sub-elements appear. Learn XML Schema (3): More Complex Schema Documents with Chubs and Sun Yuan
This time we give a more complex document:
Address.xml ---------------
Address.xsd ----------------- 1: xml version = "1.0"?> 2: Type = "xsd: string" /> 17: Customer2.xml --------------- That is like this to write Schema document: Customer2.xsd ------------------ 1: XML Version = "1.0"?> 2: Very simple, after the First look at this simple order data instance document: Order.xml --------- Suppose Order.xsd -------------------- 1: xml version = "1.0"?> 2: Similarly, if you want to define a minimum, you can use Minoccurs, such as the following: If the booking data above, you can order any one of the book name or book number, the instance document may be as follows: Order2.xml ----------------- At this time, you should write the SCHEMA document and you need to use the Choice element. Order2.xsd ------------------------- 1: XML Version = "1.0"?> 2: Order3.xml ----------------- It is defined when the How to modify the Schema documentation? Order3.xsd ---------------- 1: XML Version = "1.0"?> 2: There are 44 simple types built in XML Schema. They are published in the second part of the XML Schema recommended standard, which is a hierarchical diagram of a built-in type: http://www.w3.org/tr/2001/pr-xmlschema-2-20010330/Type-hierarchy.jpg Tong Xun XML Schema (9): Customized Simple Type What should I do if the 44 types of the built-in simple type cannot meet the requirements? Learn the custom simple type below. (XML scalability is fully reflected here) For example, this example document: Order4.xml ----------------- ID is a standard ISBN code, how do we define this ISBN coding? Value = "/ d {1} - / d {4} - / d {4} - / d {1}" This is a regular expression, about the regular expression, later introduces. Hey! Using this customized simple type, we can rewrite the Schema documentation: Order4.xsd --------------- 1: XML Version = "1.0"?> 2: If we have prior to determine how only 3 is only 3, that is, only 3 ISBN is optional, what should I do? We can use Enumeration elements to list. Among them, MININCLUSIVE, MAXINCLUSIVE represents the value range of this type, respectively. So the final revised Schema document is as follows: ORDER4-1.XSD ---------------------- 1: XML Version = "1.0"?> 2: For example, in the Order.xml instance document: In this regard, we use an Attribute in the Schema document: Order.xsd --------- Here we told the id attribute type as a custom data type IDTYPE. Moreover, use the USE attribute of the Attribute element to define whether it is a must. Required is a must value, Optional is an optional value, and Prohibited is no attribute value. So how do we define for the default values of attributes? For example: We can also define it with another attribute of attribute element default: So, we can rewrite a Schema document: ORDER2.XSD -------------- The above attributes We define that we can also use the property group to rewrote the Schema document. ORDER3.XSD ---------------- 1: