I have an XML collection like this:
<test>
<test1></test1>
<test2></test2>
<test3>
<bla1></bla1>
<bla2></bla2>
</test3>
<test3></test3>
</test>
I want to get all the nodes except for the test3 nodes. I have tried /*[not(name()='test3')], but it does not work.
Also, is it possible with XPath to add a node to an XML collection? How can I do this?
Say I have XML like this:
<rootnode>
<node1></node1>
</rootnode>
and I want to add another node. How can I do this with XPath, or is this impossible?
I want to get all the nodes except for the test3 nodes (and its innernodes). so if there is a <bla> in test2, I want to get it.
Finally, say that I want to filter the test3 nodes by index. So I want to remove all test3 nodes except for the first one (or the second or third, defined by the index I give).
How would one do this?
1: You were only searching the root, but not the descendant nodes. Also, the
name()check should be avoided because it is unreliable when prefixes and namespaces are being used. Try this:2: XPath is querying XML only. However, there ar related technologies such as XSLT and XQuery which allow the transformation of XML. Or you can use a DOM in a programming language where you use XPath to identify the nodes and then operations on the DOM to modify them.