Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing xml comments from file

Status
Not open for further replies.

moonhead

Technical User
Apr 24, 2002
11
GB
how can you remove xml tags from a file

file:
=======================================================
<!-- NB: All suites del.batches will be run at the beginning followed by the
rmhist.batches
to ensure that all msisdns are in a suitable position to be used
-->

<batch_script>
regr6_tmob_susp_del.batch
</batch_script>
<batch_script>
regr22_adhoc_del.batch
</batch_script>
<!-- <batch_script>
regr2_del.batch
</batch_script> -->
<batch_script>
regr1_del_t9.batch
</batch_script>
<batch_script>
regr1_del_t10.batch
</batch_script>
<!-- <batch_script>
regr8_del.batch
</batch_script> -->
======================================================


all i want left is the uncommented text

i have tried the following subs so far
$stre=~s/<\!\-\-([a-zA-Z\.\s\n])*\-\-\>//go; print “$1”;
$stre=~s/<\!\-\-.*.\-\->//mg;
$stre=~s/<.*>//g;

i have had trouble with the spaces tabs and other formatting

can you help
Thanks
ANDY



 
$stre =~ s/<!--\s+.*?\s+-->//gs;

I think that will do it. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
you get problems with multiline comments.
in SED: /^<!--/,/-->$/d will purge the comments
in PERL:
open the file
set a var for print, $print = yes
while read it
if you see <!-- set $print = no
if you see --> reset $print = yes
if $print == yes print the line
sure this is an idea, has to be programmed correctly. ------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top