JKI Discussion Forums
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Creating ordered elements in XML

#1
User is offline   Jim Kring 

  • Group: JKI Team
  • Posts: 1,211
  • Joined: 15-March 06
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.09K)
Number of downloads: 200

Front Panel

Attached Image: monthly_05_2008/post-2-1210377236.png

Block Diagram
Attached Image: block_diagram.png
0 kudos

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic