0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

This looks like it should work

//DoAction[*/EndAction or */Stop]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.