Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using selectNodes, How can i ... 1

Status
Not open for further replies.

trentj

Programmer
Apr 23, 2003
4
GB
Hi
example
<root>
<node id=&quot;1&quot; action='delete'/>
<node id=&quot;2&quot; action='update'/>
<node id=&quot;3&quot; />
<node id=&quot;4&quot; />
</root>
How can I select the nodes that don't have action='delete' attribute.

I can use
.selectNodes(&quot;/root/node[@action!value() != 'delete']&quot;);

or even

.selectNodes(&quot;/root/node[@action != 'delete']&quot;);

But these two only return nodes that actually have the action attribute, even if it's action=&quot;&quot;

So basically I need to select nodes that &quot;don't have an attribute of action&quot;. then I can add an 'or action != delete'.

I don't know if it can be done at all
Any suggestions or workarounds would be appriciated please
Thanks

Trentj
 
why dont u use childnodes and loop through them and select only those who dont have attribute action=delete
 
because i still don't know how to test if an attribute exists on the node + there are other children that I am not concerned about eg
<root>
<node id=&quot;1&quot; action='delete'/>
<node id=&quot;2&quot; action='update'/>
<node id=&quot;3&quot; />
<node id=&quot;4&quot; />
<diff_node id=&quot;1&quot;/>
<diff_node id=&quot;2&quot;/>
</root>

you may suspect I ma newish to xml :)

Thanks
 
because i still don't know how to test if an attribute exists on the node + there are other children that I am not concerned about eg
<root>
<node id=&quot;1&quot; action='delete'/>
<node id=&quot;2&quot; action='update'/>
<node id=&quot;3&quot; />
<node id=&quot;4&quot; />
<diff_node id=&quot;1&quot;/>
<diff_node id=&quot;2&quot;/>
</root>

you may suspect I am newish to xml :)

Thanks
 
//node[not(@action) or @action=&quot;delete&quot;]

-pete

 
Thanks very much palbano, this works perfect for what i need, using node[not(@action) or not(@action='delete')]

You da Man

Trent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top