[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

Read XML data thru actionscript

I'm writing the actionscript to read an external xml file. However, the nodeType of the data are type 1. Therefore, the nodeValue become "null".

What can I do if I want to get the data correctly without the tag ?

my actionscipt like this :

     /* xml loaded */
     ...
     var Sales = this.childNodes;
     
     for(i = 0; i < Sales.length; i++) {
          trace(Sales[i].childNodes[i]);
          trace(Sales[i].childNodes[i].nodeName);
          trace(Sales[i].childNodes[i].nodeType);
          trace(Sales[i].childNodes[i].nodeValue);
     }
It get the correct nodeName and return the nodeType as 1. If I want to get the data correctly, the nodeType need to be 3. How to make it ?

this is part of the xml file :

     <Sales>
          <CompanyName>ABC</CompanyName>
          <SalesName>John</SalesName>
          <Tel>1234 5678</Tel>
          <Mobile>1234 5678</Mobile>
          <Fax>1234 5678</Fax>
          <Email>john@abc.com</Email>
          <Other>Peripherals</Other>
     </Sales>      
     <Sales>
          ...
     </Sales>      

Would anyone know how's to do that ??

Many thanks,
sL
0
sLso
Asked:
sLso
  • 3
  • 2
1 Solution
 
blue-genieCommented:
Hi, i'm not sure I understand your problem.

"However, the nodeType of the data are type 1. Therefore, the nodeValue become "null".
It get the correct nodeName and return the nodeType as 1. If I want to get the data correctly, the nodeType need to be 3.

i don't understand any of that, what exactly are  you trying to achieve and return.
what are all your trace statements outputting in comparison to what you want it to output?

blu.
0
 
sLsoAuthor Commented:
I just want to output the data only, without the tags.

that's mean,
     <Sales>
          <CompanyName>ABC</CompanyName>
          <SalesName>John</SalesName>
          <Tel>1234 5678</Tel>
          <Mobile>1234 5678</Mobile>
          <Fax>1234 5678</Fax>
          <Email>john@abc.com</Email>
          <Other>Peripherals</Other>
     </Sales>      
     <Sales>

now, it can return the nodeName "CompanyName", and nodeType as 1 as well. I also want it can return the data "ABC" only.
0
 
blue-genieCommented:
try this:

myXML = new XML();
myXML.load("myMenu.xml");
myXML.ignoreWhite = true;
myXML.onLoad = processXML;
function processXML() {
      wordArray = new Array();
      for (var n = 0; n<myXML.firstChild.childNodes.length; n++) {
            wordArray[n] = myXML.childNodes[0].childNodes[n].childNodes[0];
            trace(wordArray[n] add " array items");
      }
}
The trace ouput is as follows:

ABC array items
John array items
1234 5678 array items
1234 5678 array items
1234 5678 array items
john@abc.com array items
Peripherals array items


happy?

blu.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sLsoAuthor Commented:
Thx a lot, blu. !!
0
 
nishasrilankanCommented:
Thanks...blu..(Even I had this problem..but I skipped the problem and used alternate method with changing the structure of the XML file)
0
 
blue-genieCommented:
u're both very welcome.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now