Reputation: 2249
I am trying to use xmlStarlet to delete a particular element in an XML file and I am having problems with the XPath specification. This is the node/element that I need to delete, i.e., specify in XPath:
<ShowFrame/>
<DoAction>
<actions>
<Stop/>
<EndAction/>
</actions>
</DoAction>
<ShowFrame/>
The problem is that there are other DoAction elements with an actions child that I do not want to delete. Only the DoAction elements with a child actions which has those 2 children: Stop and EndAction. The DoAction elements that I do not want to delete have different children in the actions child.
When I use this XPath specification in the delete xmlStarlet command only the Stop descendant is deleted:
"/swf/Header/tags/DoAction/descendant::actions/descendant::Stop"
but I want to delete the complete DoAction element. Actually, I really need to also delete the ShowFrame element following the DoAction element so there is not 2 adjacent ShowFrame elements remaining after the deletion.
I have been trying to study the XPath spec but I don't understand it. The examples I find use attributes but there are no attributes in this XML file.
Any help with this would be greatly appreciated.
Thanks,
-Andres
Upvotes: 0
Views: 239
Reputation: 89325
You can try this way :
/swf/Header/tags/DoAction[actions[Stop and EndAction]]
Above xpath select DoAction
element with child actions
contains both Stop
and EndAction
children.
Upvotes: 1
Reputation: 5998
This looks like it should work
//DoAction[*/EndAction or */Stop]
Upvotes: 0