These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Is there a way to retrieve data from a specific XML tag?

jtstanish
Registered: Jun 4 2010
Posts: 20

If I am on a field, can I use the field name to search an XML file and get data from that element to populate the current field?

Joseph Stanish

My Product Information:
Acrobat Pro 9.3.1, Windows
dotnetwiz
Registered: Jun 8 2010
Posts: 57
Sure, you can use the XMLData.parse() and XMLData.applyXPath() method to query an XML file using any arbitrary criteria, including a field's name.
jtstanish
Registered: Jun 4 2010
Posts: 20
That sounds very promising! I would like to try this.
Can you offer any additional details?
I can provide a sample Acrobat for and an XML file with data, I would appreciate a snippet of JS to load one field.

Thanks.
Joe

Joseph Stanish

dotnetwiz
Registered: Jun 8 2010
Posts: 57
You can try this out in the console window.
There are two ways of retrieving values--one uses the XMLData.applyXPath() method (more flexible) and the second one uses a simplified XFA object syntax. I've illustrated each method, the first for retrieving the last name and the second for retrieving the first name.

var c_sNAMEXML = "<?xml version='1.0'?>" +
"" +
"" +
"PersonLookupByName" +
"003" +
"" +
"" +
"John" +
"Doe" +
"" +
"";var l_oXML = XMLData.parse(c_sNAMEXML, false);
var l_sFirst = l_oXML.RequestMessage.Payload.FirstName.value;
var l_sLast = XMLData.applyXPath(l_oXML, "//RequestMessage/Payload/LastName").value

console.println(l_sFirst + " " + l_sLast);

You can then use the doc.getField() method to populate the field. If your field name were "firstname", you'd do something like

doc.getField("firstname").value = l_sFirst;

Hope this helps.
Good luck!