tags:

views:

31

answers:

1

Say that element B is a child of element A. Is there a way to make sure that for each A, the number of B elements is unbounded as long as it is consistent across A elements?

For example, the following would validate:

    <A>
       <B/>
       <B/>
    </A>
    <A>
       <B/>
       <B/>
    </A>

Because both the first and last <A> tags have two <B> elements.

But the following would not:

    <A>
       <B/>
       <B/>
       <B/>
    </A>
    <A>
       <B/>
       <B/>
    </A>
Because the first <A> element has three <B> elements while the second <A> element has two <B> elements.

+1  A: 

It's not possible to accomplish this using just XSD 1.0 due to co-constraints.

A co-constraint is constraint between two or more values. A co-constraint may exist between elements, or elements and attributes, or attribute and attribute. A co-constraint may exist within a single XML document, or across multiple XML documents. (Source)

You can check this article about extending schemas for different approaches in overcoming this kind of limitations.

It seems XSD 1.1 assertions will come to the rescue when they become standard.

antispam