Reputation: 69
The case is
<a>
<p id="1" userName="administrator" password="xxx" />
</a>
If I use "/a/p" as xpath query, then it will return
<p id="1" userName="administrator" password="xxx" />
However, I just want to display attribute id and userName, how could I do that?
Besides, I don't want to use any xpath standard function.
Upvotes: 0
Views: 314
Reputation: 163352
XPath (1.0 or 2.0) can only return nodes that were present in your input document, it cannot create new or modified nodes. For that you need XSLT or XQuery.
You can return strings, numbers, or booleans that are constructed from the nodes in the input document - but doing so without use of any standard functions sounds like masochism.
Upvotes: 0
Reputation: 89295
You can try using @
at the beginning of attribute name to address an attribute in XPath, for example :
/a/p/@id
or to get both id
and userName
at once :
/a/p/@*[name() = 'id' or name() = 'userName']
or if you meant to get all attributes excluding password
(since you have 'exclude' tag in question) :
/a/p/@*[name() != 'password']
UPDATE :
Responding to your comment, there is actually a very limited workaround in XPath 1.0 using concat()
function :
concat(/a/p/@*[name() = 'id'], ', ', /a/p/@*[name() = 'userName'])
Upvotes: 1