views:

36

answers:

2

Greetings,

I need to remove tags (about 1000) within an XML file. I tried it with jquery, but with no success:

<html>
<!--jquery app removes specific <t2_patch ...>-tag -->
<script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;
</head>
<body>

<button>Kill t2_patch-tags </button>
<script>
        $("button").click(function () {
    $('/home/dan/series14AreaListOnly.xml').remove('t2_patch');
});
</script>
</body>
</html>

My aim is to remove t_patch -tags within an 300MB large XML file. Is this approach I did so far ok, or am I completely wrong. How can I save the changes ? (Because the remove() function actually does not remove anything directly on the xml file ?).

Thanks in advance for any hints and with best regards

Daniyal

A: 

Your best bet is to set up a backend php script and ping it what entities to remove and wait for a callback, much faster and reliable, less hackable because what if someone does:

 $('/home/dan/series14AreaListOnly.xml').remove('*');
RobertPitt
A: 

Why don't XSLT? And, what is the meaning of remove tags in XML?

If you mean to strip of the element, this stylesheet removes any t2_patch element in input:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="t2_patch"/>
</xsl:stylesheet>

If you mean to strip of the element but keeping its content, this stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="t2_patch">
        <xsl:apply-templates select="node()"/>
    </xsl:template>
</xsl:stylesheet>

Note: Overwriting the identity rule.

Alejandro