Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSD question with abstract class/derived and <xsd:all>

Status
Not open for further replies.

ToCon

Programmer
Feb 3, 2009
2
US
XSD seems to have a limitation when trying to create an abstract class and a derived class. It seems to want the elements in both to be enclosed in <sequence> and not in <all>.

For instance, the XSD at the bottom of this post is correctly parsed.

But, if i change those <sequence> elements to <all>, there is a parsing error. As far as i know, the only difference should be whether the elements within the classes are required to be in sequence or not (our server does not require that they be in sequence). But, my XSD parser objects to <all> being within an Extension.

So, does anybody know how to handle the case illustrated, if the elements are not required to be in sequence?

Thanks,
tom
Code:
-----XSD example, this works, but not with <all>--------
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="elementFormDefault="qualified"
xmlns="xmlns:mstns="xmlns:xs="xmlns:xsd=">
<xsd:complexType name="basec" abstract="true">
<xsd:sequence>
<xsd:element name="e1"/>
<xsd:element name="e2"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="derived">
<xsd:complexContent>
<xsd:extension base="basec">
<xsd:sequence>
<xsd:element name="e3"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xs:schema>
 
The all group has a special nesting construction. It must only appear "at the top-level of any content model".
[tt]
[1] -quote-
ref section 2.7

There exists a third option for constraining elements in a group: All the elements in the group may appear once or not at all, and they may appear in any order. The all group (which provides a simplified version of the SGML &-Connector) is limited to the top-level of any content model. Moreover, the group's children must all be individual elements (no groups), and no element in the content model may appear more than once, i.e. the permissible values of minOccurs and maxOccurs are 0 and 1.
-unquote-
[/tt]
and
[tt]
[2] -quote-
ref
XML Representation Summary: all Element Information Item
<all
id = ID
maxOccurs = 1 : 1
minOccurs = (0 | 1) : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, element*)
</all>

<choice
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>

<sequence
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (element | group | choice | sequence | any)*)
</sequence>

Each of the above items corresponds to a particle containing a model group, with properties as follows (unless minOccurs=maxOccurs=0, in which case the item corresponds to no component at all):
-unquote-
[/tt]
You see all connector could not appear as child of sequence or choice or all connectors.

That give you the theoretical bases of the error.
 
Thanks tsuji - i do see the basis for the error.

But, do you (or anybody) know of a solution? How CAN this situation be expressed in XSD?

None of the three choices, <all>, <sequence>, or <choice> fits our XML instance. Its legal in XML, but i cannot see how to express it in XSD!

Here are our requirements:
o Server does NOT enforce sequence; elements can be in any order
o Want to create abstract base class and extend it in derived classes with <extension>.

Thanks again!
Tom


 
The schema root is completely off the mark, if you do not know. The rest, I leave for the others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top