I believe that a more general approach would be to use another XML-oriented tool such as XSL (T) (don't be afraid, he doesn't like it), but it can come in handy if you need to work with XML (don't be afraid, nobody doesn't like it).
So here we go:
This is your XSL file (it copies all materials in the source XML file and replaces the nodes that you want to delete with blank lines). Finally, it prints it out, making it more attractive, and then if you replaced it using a regular expression.
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" > <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="nmo | blue"/> </xsl:stylesheet>
This is my example that I used for testing:
<?xml version="1.0" encoding="utf-8"?> <nodes> <qwerty option="1"> <nmo>sdfsdf</nmo> <blue>sdfsdf</blue> </qwerty> <nodes> <qwerty option="1"> <nmo>sdfsdf</nmo> <blue>sdfsdf</blue> </qwerty> </nodes> <nodes> <qwerty option="1"> <nmo>sdfsdf</nmo> <blue>sdfsdf</blue> </qwerty> <other node=""/> <nodes> <qwerty option="1"> <nmo>sdfsdf</nmo> <blue>sdfsdf</blue> </qwerty> <qwerty option="1"> <nmo>sdfsdf</nmo> <blue>sdfsdf</blue> </qwerty> <qwerty option="1"> <nmo>sdfsdf</nmo> <blue>sdfsdf</blue> </qwerty> </nodes> </nodes> </nodes>
And this is the result that I get:
<?xml version="1.0"?> <nodes> <qwerty option="1"/> <nodes> <qwerty option="1"/> </nodes> <nodes> <qwerty option="1"/> <other node=""/> <nodes> <qwerty option="1"/> <qwerty option="1"/> <qwerty option="1"/> </nodes> </nodes> </nodes>
Notice how he also closed qwerty nodes.
The command line for this will look something like this:
xsltproc ./remove-nodes.xsl ./nodes-to-be-removed.xml > result.xml
You can run it from the Emacs shell or use any Emacs function to call / create a process with it, etc. man xsltproc for more information - this is a really basic use. It was installed on my Fedora, but I would suggest that, thanks to the widespread XML around the world, it will either already be installed on the Mac, or it must be installed in some way.
user797257
source share