|
-
June 18th, 2009, 09:27 AM
#1
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
-
June 23rd, 2009, 04:48 AM
#2
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>
-
June 23rd, 2009, 06:05 AM
#3
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
-
June 23rd, 2009, 06:32 AM
#4
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.
-
June 23rd, 2009, 08:42 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|