Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

XMLData.applyXPath

Avatar

Former Community Member
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

Avatar

Former Community Member
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);

Avatar

Former Community Member
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?

Avatar

Former Community Member
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.

Avatar

Former Community Member
Hit Ctrl-J when th eform is rendered. The java console will only appear if you are using Acrobat.

Avatar

Former Community Member
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)