all groups > flash data integration > august 2006 >
You're in the

flash data integration

group:

reading in XML data


Re: reading in XML data Raymond Basque
8/17/2006 10:42:53 AM
flash data integration:
You need to wait for the xml data to complete loading before assigning
values to your variables.


var VoucherNumbers:XML = new XML();


function doAfterXmlDataIsLoaded(){
//read the XML data
var vnData:XMLNode = VoucherNumbers.firstChild;
var vnVoucherNo:XMLNode = vnData.firstChild;
var vnGood:XMLNode = vnVoucherNo.firstChild;
trace(vnGood);
}

//after loading is complete, trace the XML object...
VoucherNumbers.onLoad = function(success) {
if(success){
trace(VoucherNumbers);
doAfterXmlDataIsLoaded();
}
else{
trace("oops!");
}
}

VoucherNumbers.load("VoucherNumbers.xml");

Re: reading in XML data Raymond Basque
8/17/2006 11:52:54 AM
var VoucherNumbers:XML = new XML();

VoucherNumbers.ignoreWhite=true; // <<<<=======

reading in XML data Goo101
8/17/2006 1:52:37 PM
I have written the following code to access data stored in an XML file . . .

//load the required data from the VoucherNumbers XML file
var VoucherNumbers:XML = new XML();
VoucherNumbers.load("VoucherNumbers.xml");

//after loading is complete, trace the XML object...
VoucherNumbers.onLoad = function(success) {
trace(VoucherNumbers);
}

//read the XML data
var vnData:XMLNode = VoucherNumbers.firstChild;
var vnVoucherNo:XMLNode = vnData.firstChild;
var vnGood:XMLNode = vnVoucherNo.firstChild;
trace(vnGood);

The XML file is loading ok because the "trace(VoucherNumbers);" statement is
displaying the layout and all the data held in the XML file. The problems start
when I attempt to access this data using the XMLNode object, the
"trace(vnGood);" statement is returning no data whatsoever.

Can someone please explain what I'm doing wrong? Please, this is beginning to
drive me mad!

Thanks in advance.
Re: reading in XML data Goo101
8/17/2006 3:26:48 PM
Ok, thanks Raymond . . . I've made the relevant changes to my code but an still
getting some weird returns from the data . . .

My XML file is laid out as follows . . .

<?xml version="1.0" encoding="UTF-8" ?>
- <VoucherNumbers>
<GoodVoucher>20060816151601</GoodVoucher>
- <CancelVoucher>
<CancelledVoucher>20060816091501</CancelledVoucher>
<CancelledVoucher>20060816102201</CancelledVoucher>
<CancelledVoucher>20060816105401</CancelledVoucher>
<CancelledVoucher>20060816114201</CancelledVoucher>
</CancelVoucher>
</VoucherNumbers>

And the trace code is returning the following nodeType values for the
following fields . . .

function doAfterXmlDataIsLoaded(){
//read the XML data
var vnData:XMLNode = VoucherNumbers.firstChild; //nodeType = 3
var vnVoucherNo:XMLNode = vnData.firstChild; //nodeType = undefined
var vnGood:XMLNode = vnVoucherNo.firstChild; //nodeType = undefined
trace(vnGood.nodeType);
}

What am I doing wrong? Is the layout of my XML file incorrect? Do I need a DTD
for the XML file in order to be able to read it correctly?

I though I had specified the XML data correctly.
Re: reading in XML data Goo101
8/21/2006 12:00:00 AM
Once again Raymond, thank you so much for your help! 'Tis much appreciated!

I had set the ignoreWhite property to true using the 'Components Inspector'
panel but I guess it needs to be set in the code as well.
AddThis Social Bookmark Button