Using evaluateXPathAsString to get an attribute

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
kintrupf
Posts: 257
Joined: 10 Sep 2013 08:59

Using evaluateXPathAsString to get an attribute

Post by kintrupf » 06 Nov 2015 21:31

I have this simple XML fragment and want to get the contents of the "full-path" attribute using the evaluateXPathAsString function.

Code: Select all

<?xml version="1.0"?>
<container version="1.0"
    <rootfiles>
        <rootfile full-path="volume.opf" media-type="application/oebps-package+xml" />
  </rootfiles>
</container>
Using an online xpath query tool I created two different (and apparently working) xpath strings and put them into a script action. "container_xml" naturally contains the xml from above:

Code: Select all

rootFile1 = evaluateXPathAsString(container_xml, '/container/rootfiles/rootfile/@full-path');
rootFile2 = evaluateXPathAsString(container_xml, '//rootfile[@full-path]/@full-path');
Unfortunately, a following Debug condition shows both variables as empty. What did I do wrong?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Using evaluateXPathAsString to get an attribute

Post by Martin » 09 Nov 2015 19:04

Both xpath expressions work on my test device after adding the right angle bracket on the second line of the XML.
Do you get some kind of error when you execute the flow? Is there anything in the log?

User avatar
kintrupf
Posts: 257
Joined: 10 Sep 2013 08:59

Re: Using evaluateXPathAsString to get an attribute

Post by kintrupf » 10 Nov 2015 07:42

Martin wrote:Both xpath expressions work on my test device after adding the right angle bracket on the second line of the XML.
Do you get some kind of error when you execute the flow? Is there anything in the log?
Ahh, very embarrassing! Of course you're right, with an invalid XML it could not work.
I edited out a namespace and did not see that I deleted a bracket :oops:

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Using evaluateXPathAsString to get an attribute

Post by Martin » 10 Nov 2015 19:00

No problem, I'm glad it's working now.

Post Reply