samedi 9 mai 2015

How to specify a duplicate or adjacent XML element in XPath to delete it in xmlStarlet?

I am trying to edit an XML file using xmlStarlet, so I have to specify the element I want to delete in XPath, and I am having problems with the XPath specification. The XML file will contain the following:

<SoundStreamBlock>
   <data>base64 characters</data>
</SoundStreamBlock>
<ShowFrame/>

The problem I have is that, after some previous deletions, I am left with 2 of the ShowFrame elements, one after another, that is, 2 adjacent elements:

<SoundStreamBlock>
   <data>base64 characters</data>
</SoundStreamBlock>
<ShowFrame/>
<ShowFrame/>

I want to delete the duplicate ShowFrame element. Using the following XPath specification in xmlStarlet is not working:

"/swf/Header/tags/ShowFrame/preceding::ShowFrame"

This deletes all of the ShowFrame elements except the last one. I only want to delete the single duplicate ShowFrame element, that is, only when there is a ShowFrame element immediately following a ShowFrame element.

What do I need to add to the XPath spec to restrict it for this adjacent element?

Thanks,

-Andres

Aucun commentaire:

Enregistrer un commentaire