CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2005
    Posts
    112

    repeatable XML element

    Hello

    I would like to model an entity(ET) in XML that has a repeatable element.
    Code:
    <ET id="list">
       <ELEM name="description" type="string/>
       <ELEM name="list_entry" type="string"/>         
    </ET>
    I want the list_entry to be repeatable - is it just a case adding another tag
    How best to do this?

    thank you

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: repeatable XML element

    So you need multiple "list_entry" within the list?

    Then yes, you can just repeat the list_entry:
    Code:
    <ET id="list">
       <ELEM name="description" type="string/>
       <ELEM name="list_entry" type="string"/>         
       <ELEM name="list_entry" type="string"/>         
       <ELEM name="list_entry" type="string"/>         
       <ELEM name="list_entry" type="string"/>         
       <ELEM name="list_entry" type="string"/>         
       <ELEM name="list_entry" type="string"/>         
    </ET>
    but alternative and perhaps more "pretty" and easier to read, you can wrap all the entries in a container tag, something like:

    Code:
    <ET id="list">
       <ELEM name="description" type="string/>
       <ET id="entries">
            <ELEM name="list_entry" type="string"/>         
            <ELEM name="list_entry" type="string"/>         
            <ELEM name="list_entry" type="string"/>         
            <ELEM name="list_entry" type="string"/>         
            <ELEM name="list_entry" type="string"/>         
            <ELEM name="list_entry" type="string"/>         
        </ET>
    </ET>

  3. #3
    Join Date
    May 2005
    Posts
    112

    Re: repeatable XML element

    thanks for your reply and info.

    what would be the best way to describe a variable number of list_entry elements though?
    could you just add attribute to indicate maximum # of instances of the list_entry
    or do you have static elements defined?

    thanks

  4. #4
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: repeatable XML element

    That depends on how you want to "display" it.

    If you're building up a Schema (XSD) file to display the structure fo the XML file, you use the XSD syntax to display sequences and occurrences.

    I'm unfamiliar with the syntax you're using, so I don't know whether it is a specific definition language or just pseudo code?
    If it is a specific definition language, I would guess there already would be some sort of defined standard for displaying relationships/sequences.

    However, if it is just pseudo code then I'd properly do something like this:

    Code:
    <ET id="list">
       <ELEM name="description" type="string/>
       <ET id="entries" entrycount="6">
            <ELEM name="list_entry" type="string"/>         
            <ELEM name="list_entry" type="string"/>         
            <ELEM name="list_entry" type="string"/>         
            <ELEM name="list_entry" type="string"/>         
            <ELEM name="list_entry" type="string"/>         
            <ELEM name="list_entry" type="string"/>         
        </ET>
    </ET>
    meaning using an attribute on the parent container tag to display the number. If you need that information of course.

  5. #5
    Join Date
    May 2005
    Posts
    112

    Re: repeatable XML element

    thank much for your helpful posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured