Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

XMLData.applyXPath

Not applicable
I cant get the following code to work.

// Create the XML stream
var parseString = "";
parseString += "";
parseString += "299.00";
parseString += "iPod";
parseString += "
";
parseString += "";
parseString += "49.95";
parseString += "case";
parseString += "
";
parseString += "
";
// Now create the DOM:
var x = XMLData.parse(parseString,false);
// Set up the XPath expression:
var xPathExpr = "//purchase/product/[name='iPod']/price";
// Now get the iPod price:
var price = XMLData.applyXPath(x, xPathExpr);
xfa.host.messageBox(price);

Your help would be appreciated.

Regards,

Kris
6 Replies
Not applicable
Try changing the last few lines to:



// Set up the XPath expression:

var xPathExpr = "//product[name='iPod']/price";

// Now get the iPod price:

var price = XMLData.applyXPath(x, xPathExpr);

xfa.host.messageBox(price.value);
Not applicable
Can you expand more upon what doesn't work? When I go into the Acrobat 9 JS console and enter the following:

// Create the XML stream
var parseString = "";
parseString += "";
parseString += "299.00";
parseString += "iPod";
parseString += "
";
parseString += "";
parseString += "49.95";
parseString += "case";
parseString += "
";
parseString += "
";
// Now create the DOM:
var x = XMLData.parse(parseString,false);
// Set up the XPath expression:
var xPathExpr = "//product[name='iPod']/price";
// Now get the iPod price:
var price = XMLData.applyXPath(x, xPathExpr);
app.alert(price.value)

select it all, and press Ctrl-Enter, it pops up a dialog saying 299.00, which is correct. What do you see when you execute this in the Acrobat JS console?
Not applicable
I had put the code in my script editor for a button click and no messagebox shows up.



Not sure where to get the Acrobat JS Console.
pguerett
Level 10
Level 10
Hit Ctrl-J when th eform is rendered. The java console will only appear if you are using Acrobat.
Not applicable
Try this. You can't use "x" as a variable name. x is a property on your button field.

// Create the XML stream
var parseString = "";
parseString += "";
parseString += "299.00";
parseString += "iPod";
parseString += "
";
parseString += "";
parseString += "49.95";
parseString += "case";
parseString += "
";
parseString += "
";

// Now create the DOM:
var xDOM = XMLData.parse(parseString,false);
// Set up the XPath expression:
var xPathExpr = "//product[name='iPod']/price";

// Now get the iPod price:
var price = XMLData.applyXPath(xDOM, xPathExpr);

xfa.host.messageBox(price.value)