7 Replies Latest reply on Jul 11, 2008 7:37 AM by Patrick Leckey

    Read external XML

      I'm using adobe designer 7 . I want to read external XML file with javascript
      there is a method XMLData.parse(String param1, Boolean param2) but it takes as parameter only string.
      How can I get external XML file convert it to string and pass it to XMLData.parse(param1, param2)?
        • 1. Re: Read external XML
          Patrick Leckey Level 3
          Embed it as a dataObject in the document and then get the contents as a string.
          • 2. Re: Read external XML
            Level 1
            Hi,
            Thanks for the answer. What is this this dataObject and how to embed it in the document? I can't find it in adobe designer 7 help.
            • 3. Re: Read external XML
              Level 1
              Look in the JavaScript Reference for Acrobat.

              Sabian
              • 4. Re: Read external XML
                Level 1
                var x = XMLData.parse( cXMLDoc, false ); this is what I find in the JavaScript Reference ,but cXMLDoc is a string variable , how can I convert my external xml to a string variable ?
                • 5. Re: Read external XML
                  Patrick Leckey Level 3
                  > var x = XMLData.parse( cXMLDoc, false ); this is what I find in the JavaScript Reference

                  The JavaScript Reference has more than 1 line in it, of that I am quite sure. He meant to look in the JS Reference for information on dataObjects - there is quite a lot of information about dataObjects in there, including examples.
                  • 6. Re: Read external XML
                    Level 1
                    You are right there are more than one line in it. But the line which I posted above is the line which parse the string cXMLDoc

                    Consider the XML document as first introduced in the example following the XMLData.applyXPath
                    method.
                    var x = XMLData.parse( cXMLDoc, false );
                    var y = x.family.name; // An XFAObject
                    console.println(y.value); // Output to console is "Robat"
                    Get information about dad.
                    y = x.family.dad.id; // An XFAObject
                    console.println(y.value); // Output to console is "m2"
                    y = x.family.dad.name.value; // y = "Bob"
                    x.family.dad.name.value = "Robert"; // Change name to "Robert"
                    y = x.family.dad.name.value; // y = "Robert"
                    y = x.family.dad.personal.income.value; // y = "75000"
                    x.family.dad.personal.income.value = "80000"; // Give dad a raise
                    • 7. Re: Read external XML
                      Patrick Leckey Level 3
                      > Consider the XML document as first introduced in the example following the XMLData.applyXPath
                      method.

                      You're not listening to us. JavaScript in Acrobat CAN NOT simply open a file and read from it. You need to use the methods to embed the file as a dataObject and then you can read its contents. Stop focusing on parsing the XML - that is easy and you already know how to do it. Read the sections of the reference regarding dataObjects - as I have mentioned already, it even gives you examples on how to embed dataObjects. That is what you need to do.