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

read xml file to array

Explorer ,
Oct 29, 2010 Oct 29, 2010

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

TOPICS
Scripting
1.5K
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

correct answers 1 Correct answer

Community Expert , Oct 30, 2010 Oct 30, 2010

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

Translate
Community Expert ,
Oct 30, 2010 Oct 30, 2010

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

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
Explorer ,
Oct 30, 2010 Oct 30, 2010
LATEST

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

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