/AXISWeb/Action/PingPOS[1]/PingStep/text()
is valid XPath for your document
But, from what I can see from the user guide of jxpath (note: I don't know jxpath at all), getValue()
is already supposed to return the textual content of a node, so you don't need to use the XPath text()
at all.
So you may use the following:
jxpc.getValue("/AXISWeb/Action/PingPOS[1]/PingStep");
Extracted from the user guide:
Consider the following XML document:
<?xml version="1.0" ?> <address> <street>Orchard Road</street> </address>
With the same XPath,
getValue("/address/street")
, will return the string"Orchard Road"
, whileselectSingleNode("/address/street")
- an object of type Element (DOM or JDOM, depending on the type of parser used). The returned Element is, of course,<street>Orchard Road</street>
.
Now about case insensitive query on tag names, if you are using XPath 2 you can use lower-case()
and node()
but this is not really recommended, you may better use correct names.
/*[lower-case(node())='axisweb']/*[lower-case(node())='action']/...
or if using XPath 1, you may use translate()
but it gets even worse:
/*[translate(node(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'axisweb']/*[translate(node(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'action']/...
All in all, try to ensure that you use correct query, you know it is case sensitive, so it's better to pay attention to it. As you would do in Java, foo
and fOo
are not the same variables.
Edit:
As I said, XML and thus XPath is case sensitive, so pingStep
cannot match PingStep
, use the correct name to find it.
Concerning text()
, it is part of XPath 1.0, there is no need for XPath 2 to use it. The JXPath getValue()
is already doing the call to text()
for you. If you want to do it yourself you will have to use selectSingleNode("//whatever/text()")
that will returns an Object
of type TextElement
(depending on the underlying parser).
So to sum up, the method JXPathContext.getValue()
already does the work to select the node's text content for you, so you don't need to do it yourself and explicitly call XPath's text()
.