Defining elements in XML Scheme

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian Partridge

    #1

    Defining elements in XML Scheme

    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

    #2
    Re: Defining elements in XML Scheme

    In article <Xns94258F11AC7 3Dipartridgeuki bmcom@9.20.142. 8>,
    Ian Partridge <i.partridge@DI ESPAM.uk.ibm.co m> wrote:

    % 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='unbo unded'>
    <xs:element name='tag1'.../>
    <xs:element name='tag2'.../>
    </xs:sequence>

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

    Patrick TJ McPhee
    East York Canada
    ptjm@interlog.c om

    Comment

    • Ian Partridge

      #3
      Re: Defining elements in XML Scheme

      ptjm@interlog.c om (Patrick TJ McPhee) wrote in
      news:bnueno$241 $1@news.eusc.in ter.net:
      [color=blue]
      > In article <Xns94258F11AC7 3Dipartridgeuki bmcom@9.20.142. 8>,
      > Ian Partridge <i.partridge@DI ESPAM.uk.ibm.co m> wrote:
      >
      > % 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='unbo unded'>
      > <xs:element name='tag1'.../>
      > <xs:element name='tag2'.../>
      > </xs:sequence>
      >
      > If it were the former, you'd want xs:choice.[/color]

      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

      Comment

      • Mark Preston

        #4
        Re: Defining elements in XML Scheme

        On Mon, 3 Nov 2003 22:22:21 +0000 (UTC), Ian Partridge
        <i.partridge@DI ESPAM.uk.ibm.co m> wrote:
        [color=blue]
        >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?
        >[/color]
        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.

        Comment

        Working...