regex - Delete tags between specific tags in XML (Notepad++) -
i used search function didn't find answer question.
i have xml structure following (example):
<task name="1b"> <person type ="xx" name="yy" height="zz"/> <person type ="xx" name="yy" height="zz"/> <person type ="xx" name="yy" height="zz"/> </task> <task name="1c"> <person type ="xx" name="yy" height="zz"/> <person type ="xx" name="yy" height="zz"/> <person type ="xx" name="yy" height="zz"/> </task>
now want delete via notepad++ tag name "1b" , tags between open , closing tag. there way in notepad? tried regex pattern didn't right way.
using regex html discouraged since leads many issues , unnecessary questions. see regex match open tags except xhtml self-contained tags. using xslt transform xml tool need here.
create utf8 encoded file remove_xml_tag.xsl
sample name , paste it:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="task[@name='1b']"/> </xsl:stylesheet>
the xsl processes each node , attribute (node()|@*
) , when encounters task
element name
attribute equal 1b
("task[@name='1b']"
) not write output.
then run xml tools plugin -> xsl transformation. see:
click ... button on right , browse xsl file.
click transform button.
a fallback solution in case have malformed xml work if have no nested task
nodes:
<task\s+name="1b">[^<]*(?:<(?!/task>)[^<]*)*</task>
Comments
Post a Comment