Getting started with Xsd

Source: Internet
Author: User

Let's take a look at the simple xsd below:

<? Xml version = "1.0" encoding = "UTF-8"?>

<Xs: schema xmlns: xs = "http://www.w3.org/2001/XMLSchema" elementFormDefault = "qualified"

AttributeFormDefault = "unqualified">

<Xs: element name = "ddd">

<Xs: annotation>

<Xs: documentation> Comment describing your root

Element </xs: documentation>

</Xs: annotation>

<Xs: complexType>

<Xs: sequence>

<Xs: element name = "bbb">

<Xs: complexType>

<Xs: choice>

<Xs: element name = "t"/>

</Xs: choice>

</Xs: complexType>

</Xs: element>

<Xs: group ref = "eg" minOccurs = "0"/>

<Xs: element name = "eee" minOccurs = "0"/>

</Xs: sequence>

</Xs: complexType>

</Xs: element>

<Xs: group name = "eg">

<Xs: choice>

<Xs: element name = "a"/>

<Xs: element name = "B" minOccurs = "0"/>

<Xs: element name = "c"/>

</Xs: choice>

</Xs: group>

</Xs: schema>

Below is an xml format that complies with this xsd:

<? Xml version = "1.0" encoding = "UTF-8"?>

<! -- Sample XML file generated by XMLSpy v2005 rel. 3 U (http://www.altova.com) -->

<Ddd xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"

Xsi: noNamespaceSchemaLocation = "D: \ WordML \ testchoice. xsd">

<Bbb>

<T> </t>

</Bbb>

<A> </a>

<Eee> </eee>

</Ddd>

Xsd analysis:

1. xsd contains an element and a group

2. ddd is a complex type that contains a sequence. The default value of minocc and maxocc is 1, this requires that each sub-element of sequence be presented only once (but this does not mean that bbb, eg, and eee in ddd can appear only once, they can appear 0 or multiple times, this depends on the definition of these sub-levels, but the validators only know that "the sub-elements of sequence must be presented once, not many ")

3. The child element of sequence. The first bbb is also of the CT type, and contains the choice with the same default value as 1, therefore, ddd must contain a structure similar to "<bbb> <t> </bbb> ".

4. The second sub-level is group, and the minocc of group is 0. This determines that the eg group can be omitted. This also indicates that the xml document that complies with this xsd changes from this point on, and there may be different xml. (Then we can see that element B can be 0 times. This also means that even if the minocc of the eg group is not equal to 0, the eg group can be invisible .)

5. Finally, the eee element, minocc = 0, which also indicates that eee can be omitted. (Similarly, if you change the value of maxocc to greater than 1, ddd can contain multiple eee instances)

It can be seen that the simplest xml that conforms to the xsd architecture only needs to contain bbb and its child elements once.

The validator takes a step by step. It only requires that the current object meet the xsd and does not predict the sublevel.

In this way, we can write xml that meets the requirements according to xsd.

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.