2 Replies Latest reply on Nov 13, 2017 3:15 PM by Thom Parker

    Read xml for text field

    roychen Level 1

      Read an attribute value of the XML file



      File a.xml, the path is: C:\Program Files\Adobe\Adobe Photoshop CC 2018\Presets\Scripts\a.xml

      The content of a.xml is:















      i want get Date.value  for text field by javascript



      i try:

      var f = new File('/C/Program Files/Adobe/Adobe Photoshop CC 2018/Presets/Scripts/Proof_2.0.xml'); 


      var xml = new XML( f.read() ); 


      var Widths = xml.child('Widths'); 




      but text field no value

      pls help me

      e pls help me

        • 1. Re: Read xml for text field
          Bernd Alheit Adobe Community Professional & MVP

          This JavaScript code will not work in Adobe Acrobat.

          • 2. Re: Read xml for text field
            Thom Parker Adobe Community Professional

            As Bernd says, the Acrobat javaScript model is a bit limited, but is can certainly handle an xml file.


            However, there is a very simple way to do this manually. If your text fields on the PDF exactly match the names of the Tags in the XML then this will work.


            1. Rename the "Mark" tag to "fields"

            2. Search for the "import Data" tool in Acrobat. This will  be on the "Prepare Forms" panel

            3. Run "import data" and select "XML" in the data type dropdown.


            That's it.


            Unfortunately there is no JS command for just importing xml data. If you reformatted the XML in XFDF gramar, then there is a command for loading XFDF.

            But if you want to keep the formatting, you can automate loading with JavaScript by reading the xml file data and parsing it with one of the built-in XML parsers, and then writing each data field separately. That's more code than I want to write here. I have code and an article on this topic at www.pdfscripting.com