Option between simple OR complex types in an XML Schema?

Steve (26)

Usenet Archive
Joined
Jul 1, 2005
Messages
14
Reaction score
0
Let's say I have an element that can contain a simple child element, OR a child element of complex type (but not both). For example, an actual XML snippet might look like this...

<ValueMapping>
<LocalValue>abc123</LocalValue>
<RemoteValue>123abc</RemoteValue>
</ValueMapping>

....or the XML might look like this...

<ValueMapping>
<LocalValue>abc123</LocalValue>
<MultiValueList>
<RemoteValue>123</RemoteValue>
<RemoteValue>abc</RemoteValue>
</MultiValueList>
</ValueMapping>

Is there an XML Schema I could write that would support both of these possibilies... allowing the "RemoteValue" to be either a simple element or a complex type of multiple elements (but not both at the same time)?
Thanks in advance!
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Steve said:
Let's say I have an element that can contain a simple child element, OR a child element of complex type (but not both). For example, an actual XML snippet might look like this...

<ValueMapping>
<LocalValue>abc123</LocalValue>
<RemoteValue>123abc</RemoteValue>
</ValueMapping>

...or the XML might look like this...

<ValueMapping>
<LocalValue>abc123</LocalValue>
<MultiValueList>
<RemoteValue>123</RemoteValue>
<RemoteValue>abc</RemoteValue>
</MultiValueList>
</ValueMapping>

Is there an XML Schema I could write that would support both of these possibilies... allowing the "RemoteValue" to be either a simple element or a complex type of multiple elements (but not both at the same time)?

You can use xs:choice likt this:

<xs:element name="ValueMapping">
<xs:complexType>
<xs:sequence>
<xs:element name="LocalValue" type="xs:string"/> <xs:choice> <xs:element name="RemoteValue" type="xs:string"/> <xs:element name="MultiValueList"> <xs:complexType> <xs:sequence> <xs:element name="RemoteValue" type="xs:string" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:sequence> </xs:complexType>
 

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

No members online now.

Forum statistics

Threads
548,051
Messages
3,104,251
Members
248,135
Latest member
tobystanx

Latest Threads

Top