I need to be able to delete all nodes with any name as long as (a) the node has no attributes or (b) the node has no inner text.
Sample XML:
<mydoc>
<delete_me />
<keep_me value="yes!" />
<but_do_not_keep_me></but_do_not_keep_me>
<should_you_keep_me>Absolutely!</should_you_keep_me>
</mydoc>
The expected output is
<mydoc>
<keep_me value="yes!" />
<should_you_keep_me>Absolutely!</should_you_keep_me>
</mydoc>
I've got the queries figured out to satisfy one condition or the other.
@xml.modify('delete //*[empty(@*)]')
This will only keep elements with an attribute. Similarly,
@xml.modify('delete //*[empty(node())]')
will remove all empty nodes. But I cannot figure out how to accomplish both. If I try to do a union |, that gives me the error XQuery [modify()]: The XQuery syntax 'union' is not supported..
Any suggestions?
'delete //*[empty(node()) and empty(@*)]'?|for "and". I had no idea you could use the actual textandto accomplish the same thing. Thank you!