Example of extracting XML parsed data elements using the Assign node

It is required to have a basic understanding of the E4X scripting language in order to extract parsed XML data elements. Reference sources for E4X are available through the Internet.

This section provides an example of extracting XML data.

<purchaseOrder>
<order>
  <item>Item 1</name>
  <price>$5.95</price>
  <description>Description of Item 1</description>
  <quantity>100</calories>
</order>
<order>
  <item>Item 2</name>
  <price>$7.95</price>
  <description>Description of Item 2</description>
  <quantity>200</calories>
</order>
</purchaseOrder>
To access XML data, create an XML list:
xmlElements = new XML(XML7500_outputData);
After creating the list, you can now extract any data from the list.
  1. To get the price of Item 2, you need to use a dot operator to drill down inside the XML list.
    var var1 = xmlElements.order[1].price;

    var1 output = $7.95

  2. To get the price of Item 1:
    var var2 = xmlElements.order[0].price;

    var2 output = $5.95

  3. To get the quantity of Item 2:
    var var3 = xmlElements.order[1].quantity;

    var3 output = 200

You can also iterate through a list using a looping statement:
xmlElements = new XML(XML7500_outputData);
var getOrder = xmlElements.order;
for(var i=0; i<getOrder.length(); i++){
	var3 += xmlElements.order.item[i];
	var4 += xmlElements.order.price[i];
}

var3 output = Item1Item2

var4 output = $5.95$7.95

In some cases, XML data has namespace defined to it. Here is an example if an XML data has myNS namespace:
< myNS : order>
< myNS : item>Item 1</ myNS : item>
< myNS :price>$5.95</ myNS :price>
< myNS :description>Description of Item 1</ myNS :description>
< myNS :quantity>100</ myNS :quantity>
</ myNS :order>
< myNS :order>
< myNS :item>Item 2</ myNS :item>
< myNS :price>$7.95</ myNS :price>
< myNS :description>Description of Item 2</ myNS :description>
< myNS :price>200</ myNS : price>
</ myNS :food>
To access data in the XML list with namespace, you will need to declare the namespace in your JavaScript code.
var myNS = new Namespace(‘namespace ULR here’);
  1. To get the price of Item 2, you need to use a dot operator to drill down inside the XML list.
    var var1 = xmlElements.myNS::order[1].myNS::price;

    var1 output = $7.95

  2. To get the price of Item 1:
    var var2 = xmlElements.myNS::order[0].myNS::price;

    var2 output = $5.95

  3. To get the quantity of Item 2:
    var var3 = xmlElements.nyNS::order[1].myNS::quantity;

    var3 output = 200

Notice that the namespace and XML element are connected by the scope resolution operator (double colon). You can also iterate through an XML list with namespace using a looping statement:
xmlElements = new XML(XML7500_outputData);
var myNS = new Namespace(‘namespace ULR here’);

var getOrder = xmlElements.myNS::order;
var gfLength = Order.length();
for(var i=0; i<gfLength; i++){
	var3 += xmlElements.myNS::order.myNS::item[i];
	var4 += xmlElements.myNS::order.myNS::price[i];
}

var4 output = Item1Item2

var5 output = $5.95$7.95