1 Reply Latest reply on May 29, 2008 10:59 AM by (Olav_Kvern)

    ImportXML: file vs. string ?

      Hello!

      I am working on some XML import solutions for work and have learned quite a bit!  I already have the basic XML import and XML rules written and it works great.  However, I have come to a point where I would like to parse a string into XMLElements.

      I know importXML() will import an xml file and propagate the xml structure within the InDesign document.  However, I would like to know if you can do this on a string.

      For example, say I have a string: "This big sly fox jumps over the dog."

      This string was taken from untagged text sitting in my InDesign document somewhere.  I would then like to parse that string somehow and replace that text in the document with the actual XML structure/elements extracted from the string.

      Any ideas on how to do this?

      Thanks a ton!!
      - Dimitri
        • 1. Re: ImportXML: file vs. string ?
          Level 1
          Hi Dmitri,

          Really, the easiest thing to do in this case is to write the XML out to a file and then import it into the structure. You could use the JavaScript XML object like this:

          var myString = "This big sly fox jumps over the dog";
          var myXMLElement = new XML(myString);

          ...and then parse the XML, creating XML elements in the InDesign XML structure as you find each element in the JavaScript XML object, but it's still easier (and much faster) to use a temporary file.

          Thanks,

          Ole