Copy link to clipboard
Copied
Hello,
I am having some trouble loading xml data into an array.
here is my sample code:
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("JobSeekerXML.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void
{
myLoader.removeEventListener(Event.COMPLETE, processXML);
myXML = new XML(e.target.data);
trace("length = "+myXML.length());
for (var p:int=0;p<myXML.length();p++)
{
trace(myXML.JobNumber
);
trace(myXML.JobTitle
);
}
}
and here is the XML
<?xml version="1.0" encoding="UTF-8"?>
<Jobs>
<JobNumber>296634</JobNumber>
<JobTitle>Engineer</JobTitle>
<JobNumber>12345</JobNumber>
<JobTitle>Engineer design</JobTitle>
</Jobs>
the problem i am having is that, the length is tracing back 1 when it should be 2.
i am trying to loop through the xml length and fill an array with its data.. the array is not shown in this code sample because i am stuck at this part.
i am kinda new to XML so please tell me if my stucture of nodes is the problem.
but i am not getting the right lenth of the XML it should be 2 but it says 1.
please help, thank you
Copy link to clipboard
Copied
myXML.length() is one and myXML.JobNumber.length() is two and myXML.JobTitle.length() is two.
you might want something like:
<?xml version="1.0" encoding="UTF-8"?>
<Jobs>
<job>
<JobNumber>296634</JobNumber>
<JobTitle>Engineer</JobTitle>
</job>
<job>
<JobNumber>12345</JobNumber>
<JobTitle>Engineer design</JobTitle>
</job>
</Jobs>
Find more inspiration, events, and resources on the new Adobe Community
Explore Now