IDAT106- XML Parsing

After several hours I’ve managed to cobble together some actionscript 3 to parse the XML information outputted by the program we are using.

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("data.xml"));

function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
Parse(xmlData);
}

This loads and reads the XML document and sends it to be Parsed.

This is the start of the code seeks out data by its tags and puts it into array. An if statement is used for each tag and i++; is used within the last if to cycle the array index.

var address = new Array(); ...

function Parse(Input:XML):void {
var Children:XMLList = Input.item.children();

for each (var Info:XML in Children) {

if (Info.name() == "address") {
address[i] = Info;
}
...

Inorder to load date information which comes in this form: 4/03/2010 11:53:33, into a form the times can be compared to find the greatest and lowest of all of them I used substring to extract them and then joined the data back together.

Fdetect[i] = temp.substring(11,13) + temp.substring(14,16) + temp.substring(17,19);

if (Fdetect[i] <>
style="font-size:78%;">Earliest = Fdetect[i];
}

If the current value is less then the stored lowest value then it replaces it. This allows me to automatically find the earliest and latest time for all of the data which is useful for visually representing it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.