tags:

views:

312

answers:

2

I am using a xsd schema file; there I specified an ordered list. When parsing an XML node of the kind...

<myOrderedList> "element_1" "element_2" "element_3" </myOrderedList>

(which is valid XML syntax)

...all XML parsers I know parse this as a single node element. Is there a way to get the XML parser parse this list for me (return it as a list or an array or whatever) or do I always have to parse it myself?

A: 

Why not make use of XML's ability to structure your data, and put each element in it's own XML element ? e.g.

<myOrderedList>
   <element>1</element>
   <element>2</element>
   <element>3</element>
</myOrderedList>

etc. Otherwise you're having to implement parsing (albeit in a simple fashion) on top of the parsing effort that the XML parser is performing for you ?

If you do the above, the parser will return you the ordered list without any further work, and/or you can process it more easily using standard XML tooling like XSLT/XQuery etc.

Brian Agnew
A: 

Values in a list type are always separated by whitespaces so you can easily pass that through a tokenizer to get the list of values. There are technologies like XSLT 2.0 schema aware that will see the list of values for such an element.

Using elements as proposed in the other answer is also a solution and may ease your processing. In XML child nodes are ordered so you should not worry about that. A possible representation would be:

<myOrderedList>
   <value>element_1</value>
   <value>element_2</value>
   <value>element_3</value>
</myOrderedList>
George Bina