2 Replies Latest reply on Mar 1, 2016 1:50 AM by Loic.Aigon

    How to Pass XML from JS to JSX in an HTML5 Extension

    mlavie Level 1

      Hi All,


      I am using ExtensionBuilder 3, html5/js/jsx to create an Extension for InDesign CC 2015.1



      I create a large XML in JavaScript. Currently, it is a simple string with de facto XML content (for lack of any better known way to handle this it appears that JS in the Extension environment does not support E4X or any other XML managing technique out of the box).


      I need to pass it to JSX.


      The only way I know how to do this is to take the JavaScript string and pass it as a string parameter to JSX. The JSX then does a call like: myXml = new XML(xmlString)


      This is SLOW - I have an XML string up to 30 MB in length,


      There MUST be a better way!


      All help appreciated.





        • 1. Re: How to Pass XML from JS to JSX in an HTML5 Extension
          Vamitul Level 4

          how about writing the xml to a temporary file via the extension js, then read and process that tempfile via jsx?

          • 2. Re: How to Pass XML from JS to JSX in an HTML5 Extension
            Loic.Aigon Adobe Community Professional



            The safest way to pass data back and forth from HTML/JS to JSX is to consider your data a String object.


            So in the jsx side, that would give :

            function main() {
                 var xml = <p>bla</p>;
                 return xml.toXMLString(); //turning xml object into a regular string


            And in the HTML/JS side that would be :

            csInterface.evalScript("getXMLString()", function(result) {
                 //parsing result string as XML object
                parser = new DOMParser();
              xmlDoc = parser.parseFromString(result,"text/xml");
            //reaching value
              alert( xmlDoc.documentElement.textContent );


            But it seems like common practice is to prefer json objects. Besides XML objects in the JSX side may become unvalid with oversized xml content.