我有一些像这样的xml:“some.xml”:
<one>
<two>
<three>
<four>some text</four>
</three>
</two>
<two>
<three>
<four>some other text</four>
</three>
</two>
<two>
</two>
</one>
我可以通过搜索文本来删除“两个”元素中的任何一个:
xmlstarlet ed -d "//one/two[contains(.,'some text')]" some.xml
这将删除前“两个”节点。但我想删除所有不包含任何“三个”元素的“两个”元素。像这样:
<one>
<two>
<three>
<four>some text</four>
</three>
</two>
<two>
<three>
<four>some other text</four>
</three>
</two>
</one>
我想删除所有不包含任何“三个”元素的“两个”元素
如果我理解正确的话,那就是
xmlstarlet ed -d '//two[not(three)]'
<?xml version="1.0"?>
<one>
<two>
<three>
<four>some text</four>
</three>
</two>
<two>
<three>
<four>some other text</four>
</three>
</two>
</one>