How to create an XMLSCHEMA and XML elements

Source: Internet
Author: User
ArticleDirectory
    • 1. xml references to the schema document 123
    • 2. schema document overview 123
    • 3. Simple elements, composite elements, and attributes of Schema
    • 4. schema Constraints
    • 5. schema indicator
Schema series articles

1. xml references to the schema document 123

2. schema document overview 123

3. Simple elements, composite elements, and attributes of Schema

4. schema Constraints

5. schema indicator

The following is a schema written based on the XML file:

 

<? XML version = "1.0" encoding = "ISO-8859-1"?> <Shiporder orderid = "889923" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: nonamespaceschemalocation = "shiporder. XSD "> <orderperson> john smith </orderperson> <shipto> <Name> OLA Nordmann </Name> <address> langgt 23 </address> <city> 4000 Stavanger </ city> <country> Norway </country> </shipto> <item> <title> empire burlesque </title> <Note> special edition </Note> <quantity> 1 </quantity> <price> 10.90 </price> </item> <title> hide your heart </title> <quantity> 1 </quantity> <price> 9.90 </price> </item> </shiporder>

Method 1: General method:

<? 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>

 

Method 2: define all elements and attributes, and then use the ref attribute to reference them:

 

<? 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 "/> <X S: 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>

Method 3: define the type or type, which allows us to redefine the element. By naming simple type and composite type elements, you can specify their methods in the element type attribute type:

 

 

<? XML version = "1.0" encoding = "ISO-8859-1"?> <Xs: schema xmlns: xs = "http://www.w3.org/2001/XMLSchema"> <Xs: simpletype name = "stringtype"> <Xs: Restriction base = "XS: string"/> </Xs: simpletype> <Xs: simpletype name = "inttype"> <Xs: Restriction base = "XS: positiveinteger"/> </Xs: simpletype> <Xs: simpletype name = "dectype"> <Xs: Restriction base = "XS: decimal"/> </Xs: simpletype> <Xs: simpletype name = "orderidtype"> <Xs: restriction base = "XS: string"> <Xs: Pattern value = "[0-9] {6}"/> </Xs: Restriction> </Xs: simpletype> <Xs: complextype name = "shiptotype"> <Xs: sequence> <Xs: element name = "name" type = "stringtype"/> <Xs: element name = "Address" type = "stringtype"/> <Xs: element name = "city" type = "stringtype"/> <Xs: element name = "country" type = "stringtype"/> </Xs: sequence> </Xs: complextype> <Xs: complextype name = "itemtype"> <Xs: sequence> <Xs: element name = "title" type = "stringtype"/> <Xs: element name = "NOTE" type = "stringtype" minoccurs = "0"/> <Xs: element name = "quantity" type = "inttype"/> <Xs: element name = "price" type = "dectype"/> </Xs: sequence> </Xs: complextype> <Xs: complextype name = "shipordertype"> <Xs: sequence> <Xs: element name = "orderperson" type = "stringtype"/> <Xs: element name = "shipto" type = "shiptotype"/> <Xs: element name = "item" maxoccurs = "unbounded" type = "itemtype"/> </Xs: sequence> <Xs: attribute name = "orderid" type = "orderidtype" use = "required"/> </Xs: complextype> <Xs: element name = "shiporder" type = "shipordertype"/> </Xs: schema>
XSD Elements
XSD Element
Element
Element
Explanation
Explanation
All Specifies that the child elements can appear in any order. Each child element can occur 0 or 1 time
Indicates that child elements can appear in any order, and each child element appears 0 to 1 time.
Annotation Specifies the top-level element for schema comments
Specifies the highest level of elements for schema annotations.
Any Enables the author to extend the XML document with elements not specified by the schema
Allows the editor to extend the XML file with elements not specified by the schema.
Anyattribute Enables the author to extend the XML document with attributes not specified by the schema
Allows the editor to extend the XML file with attributes not specified by schema.
Appinfo Specifies information to be used by the application (must go inside annotation)
Specified to be appliedProgramInformation used (must be in Annotation)
Attribute Defines an attribute
Define attributes
Attributegroup Defines an attribute group to be used in Complex Type Definitions
Defines an attribute group for composite category definition
Choice Allows only one of the elements contained in the <choice> declaration to be present within the containing element
Only one element in the <choice> declaration can appear in the contained element.
Complexcontent Defines extensions or restrictions on a complex type that contains mixed content or elements only
Define extensions or restrictions on composite types that contain mixed content and elements
Complextype Defines a complex type element
The composite type element is defined)
Documentation Defines text comments in a schema (must go inside annotation)
Defines text comments in Schema (must be in Annotation)
Element Defines an element
Definition Element
Extension Extends an existing simpletype or complextype Element
Extends an existing simple or composite type element.
Field Specifies an XPATH expression that specifies the value used to define an identity Constraint
Specify an XPATH expression to specify the value used to define the identity Constraint
Group Defines a group of elements to be used in Complex Type Definitions
Defines a group of elements that will be used for composite type descriptions
Import Adds multiple schemas with different target namespace to a document
Add multiple Schemas to one file using different target namespaces
Include Adds multiple schemas with the same target namespace to a document
Add multiple Schemas to a file using the same target namespace
Key Specifies an attribute or element value as a key (unique, non-nullable, and always present) within the containing element in an instance document
Specify an attribute or element value in the element contained in the instance document to make them a "key" (special, non-zero, often exists)
Keyref Specifies that an attribute or element value correspond to those of the specified key or unique element
Defines the attribute or element value used to respond to a specified key or special element.
List Defines a simple type element as a list of values
A Value List defines a simple type element
Notation Describes the format of non-XML data within an XML document
Describe the format of non-XML data in XML documents
Redefine Redefines simple and complex types, groups, and attribute groups from an external Schema
Redefinition of simple and composite types, groups, and attribute groups from external Schemas
Restriction Defines restrictions on a simpletype, simplecontent, or a complexcontent
Define constraints on simple types, simple texts, or composite texts
Schema Defines the root element of a schema
Define the root element of the schema
Selector Specifies an XPATH expression that selects a set of elements for an identity Constraint
Specifies the XPath expression that can select a group of nodes for identity constraints.
Sequence Specifies that the child elements must appear in a sequence. Each child element can occur from 0 to any number of times
Indicates that child elements must appear in a certain order. Each sub-element can appear any time
Simplecontent Contains extensions or restrictions on a text-only complex type or on a simple type as content and contains no elements
Contains extensions and constraints of text that are only compound or simple types of text, and does not contain elements.
Simpletype Defines a simple type and specifies the constraints and information about the values of attributes or text-only elements
Defines a simple type and specifies information about attribute values or text-only elements.
Union Defines a simple type as a collection (union) of values from specified simple data types
Defines a simple type from a specified simple data type as a set of values.
Unique Defines that an element or an attribute value must be unique within the scope
Defines that an element or attribute value within the scope must be unique (no duplicates)

 

 

 

More references http://www.cnblogs.com/caoxch/archive/2006/11/17/563856.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.