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

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

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?

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.

Avatar

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile
pguerett
Level 10

03-10-2008

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

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)