Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Removing XML comments with regex

by eff_i_g (Curate)
on Oct 24, 2007 at 20:53 UTC ( [id://647018]=note: print w/replies, xml ) Need Help??


in reply to Removing XML comments with regex

You can also use an identity transform in XSLT that's coupled with an exception:
<?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" versi +on="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()" /> </xsl:copy> </xsl:template> <xsl:template match="comment()" /> </xsl:stylesheet>

Replies are listed 'Best First'.
Re^2: Removing XML comments with regex
by Jenda (Abbot) on Oct 25, 2007 at 01:03 UTC
      That's actually fairly simple and idiomatic (I recognized the match and copy everything bit right away, and the first part is verbage that goes on every stylesheet in some form). It's at least no worse than when people who don't know perl complain about perl.
      It's powerful, very easy to customize, extremely fast, and handles huge XML documents quite well :) And besides, it isn't simply outputting "Hello World." It's recursing through various structures/nodes to duplicate an entire document, allowing fine-tuned controls with the simple touch of XPath. Hurrah!

      I'd be curious to see how it benchmarks against some of Perl's XML modules. Perhaps it's overkill for something as simple as comment removal, perhaps not.
        If you use a perl module, I'd recommend XML::LibXSLT which uses the libxslt library under the hood, so perl's "speed" or lack thereof should not be an issue. I wouldn't recommend XML::XSLT for any serious XSLT processing though.

        Extremely fast? Doesn't really look like it at least in some cases, especially as the processed XML grows. have a look eg. at the benchmark section in this document about XStream. It doesn't seem to handle huge documents so well either.

        And I would definitely not call that "simple touch of XPath".

        I'll see if I can find time during the weekend to implement the comment stripping using a few modules and benchmark it against XSLT. I do bet it's an overkill.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://647018]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-19 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found