Reputation: 47
Im trying to select nodes that contain a given string in one of its attributes, but it seems that I can only do it on a certain attribute.
var tempUsers = xmlDocument.selectNodes("//Users/*[contains(@Id,'TEXT')]");
I guess that instead of @Id I can write something else to check all the attributes of a node and not only the Id.
thanks.
Upvotes: 2
Views: 12610
Reputation: 122414
You can use @*
in xpath to select all attributes, but the naive
//Users/*[contains(@*,'TEXT')]
will not do what you expect. The contains
function expects its arguments to be strings, so if you give it a node set instead it will first convert the node set to a string (by taking the string value of the first node in the set) and then use that value in the function. Instead you need to say
//Users/*[@*[contains(.,'TEXT')]]
which will find all Users
elements in the document and then select all their child elements that have any attribute whose value contains the substring TEXT
.
Upvotes: 5