SOAP and Web Services
Managing XML-based Information
15
The
XML
object’s
parse
method accepts two parameters:
●
●
param1:
A string containing the text in the XML document.
param2:
A boolean that determines whether the root node should be ignored.
Its usage is illustrated below:
// XML string to be converted into a document tree:
myXML = "<family name = 'Robat'>\
<mom id = 'm1' name = 'Mary' gender = 'F'>\
<child> m2 </child>\
<personal>\
<income>75000</income>\
</personal>\
</mom>\
<son id = 'm2' name = 'Bob' gender = 'M'>\
<parent> m1 </parent>\
<personal>\
<income>35000</income>\
</personal>\
</son>\
</family>";
// Generate the document tree:
var myTree = XML.parse(myXML, false);
// Print mom’s name:
console.println("Mom: " + myXML.family.mom.value);
// Change son’s income:
myXML,family.son.personal.income.value = 40000;
The
XML
object’s
applyXPath
method accepts two parameters:
●
●
oXML
: An object representing the XML document tree.
cXPath
: A string containing an XPath query to be performed on the document tree.
In the following example, assume that
myXML
is the document tree obtained in the
previous example:
// Obtain mom’s information:
var momInfo = XML.applyXPath(myXML, "//family/mom");
// Save the information to a string:
momInfo.saveXML('pretty');
// Give mom a raise:
momInfo.personal.income.value = "80000";
Acrobat JavaScript Scripting Guide
259