04: Reading attributes
I started making a test example just using the one row, just to see if it would work, and it wouldn't, and I got confused again, and looked over my notes, and on other pages, and wasted a lot more time :)
But I think I'm back on track again now (hopefully) and attributes is the key. It's not like the other stuff wasn't relevent, it was, but I will be expanding on it by looking at how attributes can be used to get data.
Firstly, I would just be repeating what it says HERE if I were to explain the use of attributes in XML myself.
Because I am now using attributes, the old xml file is no use. I have edited my code taking the new file's location into concideration, so you don't have to.
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("http://83.170.89.79/~gibboco/
blog/tutorials/xml/test2XML.xml"));
function LoadXML(e:Event):void
{
xmlData = new XML(e.target.data);
parseThis(xmlData);
}
function parseThis(myInput:XML):void
{var blockAttributes:XMLList = myInput.row.block.attributes();
for each (var blockValue:XML in blockAttributes) {
trace(blockValue);}
}
This example simply displays the attributes of the new file in the output.
In the code highlighted orange above, myInput is the whole XML data. We are then going through the children and the children's children (row and block) getting the grandchildren's attributes. The variable blockAttributes grabs the value of all of this.
In the pink highlighted code, we are looping through each instance of a new copy of XML, 'blockValue' within blockAttributes. For each instance of blockValue in blockAttributes, it traces back the value of blockValue (outputting it on the screen).