[Experience Summary] is the organizational structure of unordered elements in XML Schema really unsolvable?

Source: Internet
Author: User
Tags xml example

Author: Thinkhy
Date: 2010.02.06.
Keyword: XML Schema indicator choice occurs unordered Element
URL: Http://www.disandu.com /? P = 651

Waterwood XML version (http://XML.board.newsmth.net/) has had a netizen raised the following questions:

Sender: Cell (Tang Pan), email area: XML
Question: Ask an XSD question. There are multiple unordered elements.
Mail station: shuimu community (Mon Dec 21 14:29:58 2009), Email Forwarding

When designing an XSD Schema, please have a question:

Now I have three elements. I want them to appear in a composite type in any order and number. This type should
Such
What is the definition? I tried sequence or all.

For example, in the XML example below, how should the schema be defined?

<Testelement>

<A/>
<B/>
<C/>
<B/>
<A/>
<C/>
</Testelement>

This type of problem often appears on the XML version, and there is a similar discussion (http://stackoverflow.com/questions/839079/middle-way-between-xsd-all-and-xsd-sequence#839110) on stackoverflow, but it does not seem to come to a conclusion. There are three types of views on unordered elements:

  1. In the XSD Design Philosophy, unordered elements are not displayed. Therefore, element attributes in sequence are ordered, and all elements appear at most once;

  2. This problem is still in the unsolved stage, and the XSD 1.x standard will solve it;

  3. Add an element to wrap the element with the same name. For example, add an as element in the preceding example to wrap Element A in the following format:

    <As>

    <A>... </a>
    <A>... </a>
    ......
    </As>

In fact, I have encountered such problems in the project. The third solution I adopted is actually a method adopted by most people. Perhaps W3C does not advocate the unordered element data organization method, so there is no obvious solution to this problem, but W3C has not completely abandoned this design method, and the XSD standard is notoriously complex, you cannot expect to find a solution by studying the XSD standard documentation. What should I do? Inadvertently, I saw the following post in the Shui Mu XML version:

Sender: gmnicx (MR. Zhuang | 2010 perfect hair), email area: XML
Question: Re: how to implement the following requirements when using the choice label?
Mailing site: shuimu community (Tue Jan 5 17:32:46 2010)

Now, occurs is written to the choice label.
[Mentioned in the masterpiece gmnicx (MR. Zhuang | 2010 perfect hairs :]
: The choice group may appear several times (either not or multiple times)
: But the total number must appear at least once.
For example
:...................

The original choice can add the occurs attribute, so the unordered elements can be solved. See the following XSD:

<? XML version = "1.0"?>
<Xs: schema xmlns: xs = "http://www.w3.org/2001/XMLSchema">
<Xs: element name = "testelement">
<Xs: complextype>
<Xs: Choice minoccurs = "0" maxoccurs = "unbounded">
<Xs: element name = "A" type = "XS: anytype"/>
<Xs: element name = "B" type = "XS: anytype"/>
<Xs: element name = "C" type = "XS: anytype"/>
</Xs: Choice>
</Xs: complextype>
</Xs: Element>
</Xs: schema>

Choice adds two occurs attributes, and the unordered element problem is solved. From the above story, I learned two things:

1. The discussion of foreigners may not be accurate. stackoverflow has not come to a conclusion on this issue.

2. The power of the masses is endless. Forums, BBS, and blogs on the Internet all provide exchange platforms. cainiao and experts are useless and can freely express their own opinions on these platforms, the solution to the problem is often not from the Archbishop of the church, but from the point of view of every netizen, which is just as the water can sink into the river.

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.