Jump to content


Photo

Creating ordered elements in XML


  • Please log in to reply
No replies to this topic

#1 Jim Kring

Jim Kring
  • JKI Team
  • 1,267 posts

Posted 09 May 2008 - 11:55 PM

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

Attached File  Element_Ordering.vi   45.09KB   385 downloads

Front Panel

front_panel.png

Block Diagram
block_diagram.png
  • 0