Defining elements in XML Scheme

Ian Partridge

Usenet Archive
Joined
Oct 9, 2003
Messages
5
Reaction score
0
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
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
% 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.
 

Ian Partridge

Usenet Archive
Joined
Oct 9, 2003
Messages
5
Reaction score
0
(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
 

Mark Preston

Usenet Archive
Joined
Jan 11, 2000
Messages
268
Reaction score
0
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

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,224
Members
248,132
Latest member
henrywalsh

Latest Threads

Top