1 Reply Latest reply on May 23, 2012 4:10 AM by John Hawkinson

    XML: import only the body element...

    Marcos Suárez Level 1

      I need import only the body element...

       

      var myXMLFile=File.openDialog("Choose XML.......");

      myDoc.importXML(File(myXMLFile.body));

       

      But not work...!!!

       

      It this possible?

        • 1. Re: XML: import only the body element...
          John Hawkinson Level 5
          It this possible?

          Not like that!

          What you've written doesn't make much sense:

           

          var myXMLFile=File.openDialog("Choose XML.......");

          myDoc.importXML(File(myXMLFile.body));

          In this code, myXMLFile is a File object. File objects do not have .body properties, so myXMLFile.body is not valid.

          And even if a File object did have a .body property, it would presumably be some sort of XML content inside the File. But the File() constructor takes a string argument that is a filename. So File(myXMLFile.body) wouldn't work either!

           

          I think you should take a step back and make sure you understand the basics before you try to put them together like this.

           

          Since the importXML() method only takes a file, a solution is to read the XML file, pull out the <body/> element, write it to another file,and then call importXML() on the new file.

           

          Alternatively, you can create an XSLT transformation and set doc.XMLImportPreferences to mandate its use. If you're not familiar with XSLT, learning it may not be appropraite for this task.

           

          But perhaps your requirements are overly restrictive -- why can't you import the whole file and then only instruct InDesign to deal with the body element?

          1 person found this helpful