Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Removing XML comments with regex

by gasho (Beadle)
on Oct 24, 2007 at 19:39 UTC ( [id://646982]=note: print w/replies, xml ) Need Help??


in reply to Removing XML comments with regex

Is this good enough ?
while (<>) { $line=$_; chomp $line; $StartTag='<!--'; $EndTag='-->'; if (($line =~ m/\Q$StartTag\E/) .. ($line =~ m/\Q$EndTag\E/)){ $Flag=0; } elsif (($line =~/<!--/) || ($line =~/-->/)){ $Flag=0; } else { $Flag=1; } if($Flag){ print "$line\n"; } }
(: Life is short enjoy it :)

Replies are listed 'Best First'.
Re^2: Removing XML comments with regex
by tuxz0r (Pilgrim) on Oct 24, 2007 at 19:44 UTC
    I did the following (barring corner cases as mentioned previously) and it seems to strip comments just fine:
    cat t.xml | perl -e '$/ = ""; $_ = <>; s/<!--.*?-->//gs; print;'
    which gave the output:
    <Node_A> <Node_B> <Node_C> </Node_C> </Node_B> </Node_A>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found