Tip: Pretty XML Strings
I regularly use the saveXML() method, available on all node class-based objects, as a way to debug my forms (think of it as a type of introspection technique). The method outputs a string representation of the XML content of the node in question, which helps when attempting to discover the underlying object structure without a debugger…
For example, say you have a simple form with a text field and a numeric field. The following statement will output the form’s data to the JavaScript Console in Acrobat:
console.println(xfa.datasets.data.saveXML());
The result, however, isn’t very readable:
<?xml version="1.0" encoding="UTF-8"?>
<xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"
><form1
><TextField1
>asdf</TextField1
><NumericField1
>1234</NumericField1
></form1
></xfa:data
>
Though I had been using saveXML() for quite some time, I hadn’t realized that it actually takes an optional parameter, a string with a value of “pretty”, that results in much nicer output.
console.println(xfa.datasets.data.saveXML('pretty'));
results in the following pretty/readable output:
<?xml version="1.0" encoding="UTF-8"?>
<xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<form1>
<TextField1>asdf</TextField1>
<NumericField1>1234</NumericField1>
</form1>
</xfa:data>
Posted by Stefan Cameron on August 19th, 2009
Filed under Debugging,Scripting,Tips
Both comments and pings are currently closed.