Defining elements in XML Scheme

I

Ian Partridge

Hi,

I'm having some problems working out how my XML Schema should be
constructed. Simply, if I have XML like:

<basetag>
<tag1>foo</tag1>
<tag2>bar</tag2>
<tag1>foo</tag1>
<tag2>bar</tag2>
<tag2>bar</tag2>
<tag1>foo</tag1>
<tag2>bar</tag2>
</basetag>

i.e. unlimited interleaved instances of tag1 and tag2 within basetag, how
should I define my Schema to support this? I can't see how <xs:sequence> or
<xs:choice> are appropriate in this case...

Any tips greatly appreciated.

Many thanks,
Ian Partridge
 
P

Patrick TJ McPhee

% constructed. Simply, if I have XML like:
%
% <basetag>
% <tag1>foo</tag1>
% <tag2>bar</tag2>
% <tag1>foo</tag1>
% <tag2>bar</tag2>
% <tag2>bar</tag2>
% <tag1>foo</tag1>
% <tag2>bar</tag2>
% </basetag>
%
% i.e. unlimited interleaved instances of tag1 and tag2 within basetag, how
% should I define my Schema to support this? I can't see how <xs:sequence> or
% <xs:choice> are appropriate in this case...

Well, is it any of tag1 or tag2, or is it tag1 then tag2, any number
of times? From your use of interleaved, I guess it's the latter, so you
want

<xs:sequence maxOccurs='unbounded'>
<xs:element name='tag1'.../>
<xs:element name='tag2'.../>
</xs:sequence>

If it were the former, you'd want xs:choice.
 
I

Ian Partridge

(e-mail address removed) (Patrick TJ McPhee) wrote in
% constructed. Simply, if I have XML like:
%
% <basetag>
% <tag1>foo</tag1>
% <tag2>bar</tag2>
% <tag1>foo</tag1>
% <tag2>bar</tag2>
% <tag2>bar</tag2>
% <tag1>foo</tag1>
% <tag2>bar</tag2>
% </basetag>
%
% i.e. unlimited interleaved instances of tag1 and tag2 within
basetag, how % should I define my Schema to support this? I can't see
how <xs:sequence> or % <xs:choice> are appropriate in this case...

Well, is it any of tag1 or tag2, or is it tag1 then tag2, any number
of times? From your use of interleaved, I guess it's the latter, so
you want

<xs:sequence maxOccurs='unbounded'>
<xs:element name='tag1'.../>
<xs:element name='tag2'.../>
</xs:sequence>

If it were the former, you'd want xs:choice.

It is the former, sorry, I was unclear.

Basically tag1 and tag2 will each occur an unlimited number of times (or
not at all), randomly in any order.

Can I use <xs:choice> for that?

Thanks in advance,
Ian
 
M

Mark Preston

Basically tag1 and tag2 will each occur an unlimited number of times (or
not at all), randomly in any order.

Can I use <xs:choice> for that?
Yes, its a <choice> of either tag and in can occur up to the limit of
how many you want in the set - in other words, a choice that can be
repeated many times within the main tag.
 

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