Schema indicator (indicators)

Source: Internet
Author: User
Tags element groups
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
    • 6. How to create an XMLSCHEMA and XML elements
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

6. How to create an XMLSCHEMA and XML elements

Using indicators we can control the use of elements in a file. There are seven indicators:

1. sequence indicator: All, choice, and sequence;

2. Number of occurrences indicator: maxoccurs and minoccurs;

3. Group indicator: groupname and attributegroup name;

  • An indicators indicator is used to specify the order of elements.

    <All> the indicators indicator indicates that sub-components can appear in any order, and each sub-component can only appear once:

     
    <Xs: element name = "author"> <Xs: complextype> <Xs: All> <Xs: element name = "firstname" type = "XS: string "/> <Xs: element name =" lastname "type =" XS: string "/> </Xs: All> </Xs: complextype> </Xs: Element>

    <Choice> the indicator (indicators) indicates that any child element can appear: You can select only one of the multiple child components:

     
    <Xs: element name = "author"> <Xs: complextype> <Xs: Choice> <Xs: element name = "firstname" type = "XS: string "/> <Xs: element name =" lastname "type =" XS: string "/> </Xs: Choice> </Xs: complextype> </Xs: Element>

    <Sequence> the indicator (indicators) specifies that child elements must appear in a specified order:

     
    <Xs: element name = "author"> <Xs: complextype> <Xs: sequence> <Xs: element name = "firstname" type = "XS: string "/> <Xs: element name =" lastname "type =" XS: string "/> </Xs: sequence> </Xs: complextype> </Xs: Element>
  • Number of occurrences indicator: the maximum number of occurrences indicator (indicators) indicates the maximum number of occurrences of an element. The minimum number of occurrences indicator (indicators) indicates the minimum number of occurrences of an element:

    <Xs: element name = "author"> <Xs: complextype> <Xs: sequence> <Xs: element name = "firstname" type = "XS: string "minoccurs =" 0 "/> <Xs: element name =" lastname "type =" XS: string "maxoccurs =" 2 "/> </Xs: sequence> </Xs: complextype> </Xs: Element>

    TIPS: You can set the status of maxoccurs = "unbounded" to make the component appear multiple times;

  • Indicators is used to define related element groups: 1. Element groups: You must define an all, choice, or sequence element in the group declaration. The following example defines a group named "persongroup:

     
    <Xs: group name = "persongroup"> <Xs: sequence> <Xs: element name = "firstname"/> <Xs: element name = "lastname"/> </Xs: sequence> </Xs: group>

    After defining a group, you can refer to it in another group, such:

     
    <Xs: group name = "persongroup"> <Xs: sequence> <Xs: element name = "firstname"/> <Xs: element name = "lastname"/> </Xs: sequence> </Xs: group> <Xs: element name = "person" type = "personinfo"> </Xs: element> <Xs: complextype name = "personinfo"> <Xs: sequence> <Xs: group ref = "persongroup"/> <Xs: element name = "country" type = "XS: string"/> </Xs: sequence> </Xs: complextype>

    2. Attribute Group 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>

    After the attribute group is declared, we can reference it like this:

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

Others:

<Any> the element allows us to add new elements not defined by the schema in the XML document to expand the XML document;

<Anyattribute> the element allows us to add attributes not specified by schema in the XML document;

 

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

We can expand any element in the content of the "person" element (after <lastname> );

 

See the schema file "children. XSD" below:

 

<? XML version = "1.0" encoding = "ISO-8859-1"?> <Xs: schema xmlns: xs = "http://www.w3.org/2001/XMLSchema" targetnamespace = "http://www.w3schools.com" xmlns = "http://www.w3schools.com" elementformdefault = "qualified"> <Xs: element name = "children"> <Xs: complextype> <Xs: sequence> <Xs: element name = "childname" type = "XS: string" maxoccurs = "unbounded"/> </Xs: sequence> </Xs: complextype> </Xs: Element> </Xs: schema>

The following XML file (called "myfamily. xml "),Two components from different schemas are used: "family. XSD" and "Children. XSD ".:

 

 

<? 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. xsdhttp: // 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 create scalable documents! They allow documents to contain other new elements that have not been declared in the main XML schema.

 

Element substitution: Substitutiongroup

<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"/>

According to the preceding constraints, there can be two different legal XML files:

 
<Customer> <Name> john smith </Name> </customer>

Or

 
<Kunde> <navn> john smith </navn> </Kunde>

Disable substitution element: block attribute can be used to prevent other elements from being replaced by specified elements;

<Xs: element name = "name" type = "XS: string" Block = "substitution"/>

Precautions for element substitution:

1. The alternative element type should be the same as or derived from the title element. If the alternative element type is the same as that of the title element, you do not need to specify the alternative element type; 2. All elements in the element group that can be replaced (the title element and the replaceable element) must be declared as "Global element", otherwise it will not work; "Global element" is a direct sub-element under the "schema" element. "Local element" is an element nested in other elements.

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.