Xml Schema OR, XOR

V

Verticon::

I have two situations here.

1. XOR: I found I can use the 'choice' type to handle that.
2. OR: I don't know how to do

All three of these are valid:
<root>
<A />
<B />
</root>

<root>
<A />
</root>

<root>
<B />
</root>

This would NOT be valid:
<root>
</root>

How would I lay out the schema for the OR situation here?
 
J

Joseph Kesselman

Verticon:: said:
> How would I lay out the schema for the OR situation here?

"One or more instances of the choice" would permit any mixture of A's
and B's but reject the empty case.

If you want to allow ONLY A, B, or AB (not AAB, ABA, etc.)... I think
you need to spell out those three options as separate choices. XML
Schema doesn't have the ability to say "exclude/require X if Y was present".
 
V

Verticon::

I just tried to do that. I added a new choice group with A, B, and a
group of A and B. Came back with ambiguous content errors in the
schema; redefining existing nodes.
 
J

Joe Kesselman

Verticon:: said:
I just tried to do that. I added a new choice group with A, B, and a
group of A and B. Came back with ambiguous content errors in the
schema; redefining existing nodes.

That doesn't wholly surprise me, I'm afraid.

I suspect the best you can do is to set zero-to-two on the choice, and
check that they aren't the same in your application code. I'd love to
find out I'm wrong.

See recent discussion of the goals and limitations of XML Schema.
 
M

Martin Honnen

Verticon:: said:
I have two situations here.

1. XOR: I found I can use the 'choice' type to handle that.
2. OR: I don't know how to do

All three of these are valid:
<root>
<A />
<B />
</root>

<root>
<A />
</root>

<root>
<B />
</root>

This would NOT be valid:
<root>
</root>

How would I lay out the schema for the OR situation here?

This should do:

<xs:element name="root">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element name="A"/>
<xs:element name="B" minOccurs="0"/>
</xs:sequence>
<xs:element name="B"/>
</xs:choice>
</xs:complexType>
</xs:element>
 
J

Joe Kesselman

Martin said:
<xs:element name="root">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element name="A"/>
<xs:element name="B" minOccurs="0"/>
</xs:sequence>
<xs:element name="B"/>
</xs:choice>
</xs:complexType>
</xs:element>

Looks reasonable to me. Kicking myself slightly for not having
immediately seen that solution; like I said, I haven't been using schema
enough recently.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top