How can I handle this situation in an XSD schema?

My question is regarding XSD. I have XML where the root can contain a single element from a list of possible elements.

    Requires Free Membership to View


<root>
<objectA/>
</root>

<root>
<objectB/>
</root>

<root>
<objectC/>
</root>

etc.

I have had no problem creating XSD schema to handle this (using xsd:choice).My problem is that for the child element <> objectA cenario, I need two attributes for the root element.

<root>
<objectA/>
</root>

<root sender="" receiver="">
<objectB/>
</root>

<root sender="" receiver="">
<objectC/>
</root>

How can I handle this situation in an XSD schema? XSD does not have XSL capabilities such as xsl:if.
Declare an element type objectA and declare its two attributes. When the parser encounters and objectA it will look for the attributes. One way to think of it is that the XSD parser is executing the "if" logic behind the scenes rather than you specifying it in the schema.

This was first published in April 2003

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.