I'm new to using XPath so I've been fooling around with an XPath Evaluator and I'm trying to find out how to return the value of a function.
If I want to return the href
s of all the links on a page I can use the following XPath:
//a/@href
If I want to return all the links with href
s longer than 20 chars I can use this:
//a[string-length(@href) > 20]
What I can't figure out is how do I get just the lengths of all href
s?
My naive assumption was that this should do it:
//a/string-length(@href)
But it fails (as do all the variations I could think of).
How can this be done?
After digging in a bit further I saw that the XPath Evaluator I was using hard-coded XPathResult.ORDERED_NODE_SNAPSHOT_TYPE
as the result type, when I changed it to ANY_TYPE
(0) the following worked for getting the length of one link (which is what I actually need)
string-length((//a)[1]/@href)