Highlighted

XMLData.applyXPath

Avatar

19-09-2008

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

Replies

Highlighted

Avatar

25-09-2008

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);
Highlighted

Avatar

03-10-2008

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?
Highlighted

Avatar

03-10-2008

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.
Highlighted

Avatar

Avatar

pguerett

Total Posts

(val/1000)?string[".0"]}K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

(val/1000)?string[".0"]}K

Likes

611

Correct Answer

692
pguerett

03-10-2008

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

Avatar

15-10-2008

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)