Jump to content
Sign in to follow this  
Jim Kring

Creating ordered elements in XML

Recommended Posts

Sometimes, you want to explicitly state the order of XML elements. XML doesn't natively support element ordering. So, if you have XML that looks like this, you can't deterministically say that the element with "foo" data comes before element with "bar" data.

 

<element>
<data>foo</data>
 </element>
 <element>
<data>bar</data>
 </element>
 <element>
<data>monkey</data>
 </element>
 <element>
<data>fish</data>
 </element>

 

You can get around this XML limitation by explicitly adding an order/index attribute to your ordered elements. For example:

 

<element n="1">
<data>foo</data>
 </element>
 <element n="2">
<data>bar</data>
 </element>
 <element n="3">
<data>monkey</data>
 </element>
 <element n="4">
<data>fish</data>
 </element>

 

In order to work with data like this, you'll need to pre-populate the "n" attribute before you generate the XML and you'll need to post-process the "n" attribute after you parse the XML. Here's an example, that demonstrates this technique:

Example VI

Element_Ordering.vi

Front Panel

front_panel.png

 

Block Diagram

block_diagram.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use.