Page 1 of 1

Using evaluateXPathAsString to get an attribute

Posted: 06 Nov 2015 21:31
by kintrupf
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?

Re: Using evaluateXPathAsString to get an attribute

Posted: 09 Nov 2015 19:04
by Martin
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?

Re: Using evaluateXPathAsString to get an attribute

Posted: 10 Nov 2015 07:42
by kintrupf
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:

Re: Using evaluateXPathAsString to get an attribute

Posted: 10 Nov 2015 19:00
by Martin
No problem, I'm glad it's working now.