I'm new in the programming world. I'm just looking for help with some kind of code, that would delete node from bunch of xml documents.
It is possible to make something which would delete node in bunch of xml documents at once?
I'm new in the programming world. I'm just looking for help with some kind of code, that would delete node from bunch of xml documents.
It is possible to make something which would delete node in bunch of xml documents at once?
There are many different technologies you could use, which is a bit daunting if you are new to programming. Since this quite a simple task, it's probably not worth investing a lot of time learning new tools: but then it all depends on what you're already comfortable with.
Many people would use XSLT for any job that involves modifying XML documents. You could write an XSLT 3.0 stylesheet transform.xsl
like this:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="deleted-node"/>
</xsl:transform>
where "deleted-node" is the name of the nodes you want to delete (or a more complex pattern if you need it). And then you could apply this to all XML files in a directory in
, putting the result in directory out
, using the Saxon XSLT processor from the command line like this:
Transform -s:in -o:out -xsl:transform.xsl
The way this works is that xsl:mode defines the default processing to be applied to nodes if there isn't a more specific rule; shallow-copy means that you copy the tags and then move on to process the content. There's only one more specific rule, which matches the elements you want to delete; the rule is empty indicating that when you hit one of these elements, you output nothing.