Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Loading XML data into an array

New Here ,
Nov 01, 2013 Nov 01, 2013

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

TOPICS
ActionScript
405
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2013 Nov 01, 2013
LATEST

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines