simple and complex unions?

S

stevecanfield

I have xml that has nodes that either have a text value or more nested
elements. For example, both of these are valid for my <value> node:

<value>1234</value>
and
<value><object>foo</object></value>

Any clues on how I could express this in the schema (xsd)? I've
figured out how to do one or the other, but not allow either. It seems
like it should be very simple, but I'm stuck... Please help!

-sc
 
M

Martin Honnen

I have xml that has nodes that either have a text value or more nested
elements. For example, both of these are valid for my <value> node:

<value>1234</value>
and
<value><object>foo</object></value>

Any clues on how I could express this in the schema (xsd)? I've
figured out how to do one or the other, but not allow either. It seems
like it should be very simple, but I'm stuck... Please help!

I think you need to allow mixed contents theN which would not only allow
<value>1234</value> but as well <value><object>foo</object>1234</value>:
<URL:http://www.w3.org/TR/xmlschema-0/#mixedContent>
 
S

stevecanfield

I think you need to allow mixed contents theN which would not only allow
<value>1234</value> but as well <value><object>foo</object>1234</value>:
<URL:http://www.w3.org/TR/xmlschema-0/#mixedContent>

I ended up doing just that, but I'm not entirely happy with the
result. It seems to me that specifying mixed content allows *any* text
content. I'd like to limit it to just digits.

-sc
 
U

usenet

I ended up doing just that, but I'm not entirely happy with the
result. It seems to me that specifying mixed content allows *any* text
content. I'd like to limit it to just digits.

-sc

Alas, with XSD, using the mixed content is the best you can do. It
would be nice if XSD had something like xs:text similar to what Relax-
NG has so you could do:

<xs:complexType ...>
<xs:choce>
<xs:text type='xs:int'/>
<xs:element name='object' type='xs:string'/>
</xs:choice>
</xs:complexType>

Unfortunately it's not even on the radar for the next version of XSD.

HTH,

Pete Cordell
Codalogic
Visit http://www.codalogic.com/lmx/ for XML C++ data binding
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top