4 Replies Latest reply on Feb 15, 2008 12:13 PM by David Wigforss-Hv1BNN

    XML Creation

    David Wigforss-Hv1BNN Level 2
      I have three big stumbling blocks when creating XML files (thru scripting).

      1) How can I utilize variables inside my xml code.

      ex. var myRoot = new XML ("<job> <task> 1 </task> </job>")
      How can I replace the 1 with a variable?

      2) How can I have quotes appear in the elements?

      ex. <winexe> "R:\Apps\AfterEffects6\Support Files\aerender.exe" </winexe>
      It generates an error (needs a following ')' )when adding them into the code, since it's trying to terminate the '= new XML ("'

      3) How can I add "comment" code to the XML document

      ex. I need it to say: <!-- Set Frame Settings -->

      Thanks for your help!
      -Dave
        • 1. Re: XML Creation
          Mylenium Most Valuable Participant
          >1) How can I utilize variables inside my xml code.

          Concatenate and format the strings correctly:

          "<job>"+variable+"</job>"

          Variable types may need conversion with the .toString method or other operator and then should also be enclosed into quotes after they have been converted

          >2) How can I have quotes appear in the elements?

          You need to escape the characters to treat them as string literals

          "<winexe>"+"\"R:\\Apps\\AfterEffects6\""

          >3) How can I add "comment" code to the XML document

          Same as above - escape and concatenate correctly

          Mylenium
          • 2. Re: XML Creation
            David Wigforss-Hv1BNN Level 2
            Thx for the reply, Myl.

            1) Thanks - that worked perfectly. My first problem was that I didn't have the + and + surrounding my variable. Second, I later discovered that the variable definition needed to be in quotes. (ie var catType = "PSD"; ) But I got that sorted out..

            2) I couldn't get this to work..
            ("<a1>" + "\"R:\\Apps " + "</a1> <job></job>")
            XML error in line 1 Junk after document element
            ("<a1>" + "\"R:\\Apps "" + </a1> <job></job>")
            Expected: )
            ("<a1>" + "\"R:\\Apps "" + "</a1> <job></job>")
            Expected: )

            ----------------------------------
            You need to escape the characters to treat them as string literals

            "<winexe>"+"\"R:\\Apps\\AfterEffects6\""

            3) Once I can get #2 working, I'll give this a go.
            • 3. Re: XML Creation
              David Wigforss-Hv1BNN Level 2
              Not sure why I couldn't get the quotes working before... Perhaps I needed to add a space after it..

              This works:
              var catWinexe = " \"R:\\Apps\\AfterEffects6\\Support Files\\aerender.exe\" ";

              Another question:

              I've now moved onto UI creation... What I would like to do is create edittext boxes, which would populate my variables.. I'm having a problem on my first attempt..

              // Add a panel to contain the components
              win.pnlA = win.add("panel", [10, 10, 400, 450], "Settings");

              win.pnlA.displayTextLbl = win.pnlA.add("statictext", [10, 415, 100, 430], "XML Name:");
              XMLName = win.pnlA.add("edittext", [100, 415, 225, 430], 'XMLTest5');

              var logFile = new File("/c/TEMP/" + XMLName + ".xml");

              Most of the rest of the script creates lots more static and edit texts with other panels... My problem is, I'm not sure how to get the result of the edittext (in my example, XMLTest5) to appear in the variable/filename. My filename is unwantingly written as [object EditText].xml

              Thanks again for your help.
              -Dave
              • 4. Re: XML Creation
                David Wigforss-Hv1BNN Level 2
                http://www.adobeforums.com/webx/.3c062062/0

                In order to access the edittext values, you need to add .text after the variable.. So, in my case I needed:

                var logFile = new File("/c/TEMP/" + XMLName.text + ".xml");

                Thanks again, Jeff!