2 Replies Latest reply on Oct 30, 2010 11:08 AM by jkinsman

    read xml file to array

    jkinsman Level 1

      I would like to read an xml file to an array before placing it in a document. I have seen people on here do something similar but I just can't get it to work.

       

      Right now I am having to open the docuement as just a file read it into an array and then pull the elements I want with a regex expression, which is pretty tedious.

       

      It seems the framework has some pretty nice xml element functions if I could just read the file in an xml format

       

      Right now I am doing something like this to read the file

       

      myfile = new File (path to file);

      myfile.open("r");

      myothervariable = myfile.read();

      myfile.close();

       

      But I am just reading it as simple text. I can't use any of the xml properties or functions on any of this. Does this make sense?

       

      Thanks in advance for any help

        • 1. Re: read xml file to array
          Peter Kahrel Adobe Community Professional & MVP

          Do this:


          myfile = new File (path to file);

          myfile.open("r");

          myXML = new XML (myfile.read());

          myfile.close();

           

          You now have an XML object that you can parse with JavaScript. See the ESTK's JavaScript Tools Guide (in the ESTK's Help menu), the chapter entitled "Integrating XML into JavaScript" (ch. 9 in CS5).

           

           

          Peter

          • 2. Re: read xml file to array
            jkinsman Level 1

            Peter,

             

            Thanks that looks right. Haven't tried it yet. I swear I tried this but I might not have done it exactly like this. I forgot to mention that I am building this for ID4. I thoroughly went through the ESTK documentation and didn't find a read method for the xml class.

             

            Thanks

            Jesse