xpath - SQL Server XML modify remove nodes without attributes or inner text -
i need able delete nodes name long (a) node has no attributes or (b) 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 queries figured out satisfy 1 condition or other.
@xml.modify('delete //*[empty(@*)]')
this keep elements attribute. similarly,
@xml.modify('delete //*[empty(node())]')
will remove empty nodes. cannot figure out how accomplish both. if try union |
, gives me error xquery [modify()]: xquery syntax 'union' not supported.
.
any suggestions?
as per @zlk's comment above, and
keyword allowed.
@xml.modify('delete //*[empty(node()) , empty(@*)]')
works perfectly.
Comments
Post a Comment