I try remove attribute and child at once from xml like:
<xml>
<node attribute="name">
<child>name</child>
</node>
</xml>
to expected result like
<xml>
<node>
</node>
</xml>
depending on child value.
Is it even possible?
CodePudding user response:
You probably can; try using
xml ed -d '//node[child["name"]]/@attribute' -d '//node/child["name"]' file.xml
The first part deletes (-d
) the attribute
attribute of the node
node which itself has a child
child node with a name
text value; the second -d
deletes the 'child` node itself.
CodePudding user response:
Inspired by Jack, this is working solution:
xml ed -d '//node[child="name"]/@attribute' -d '//node/child[contains(text(),"name")]' file.xml