OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] How do you remove comments from XML?

[ Lists Home | Date Index | Thread Index ]

Dominica DeGrandis wrote:
> I'm writing a vb or vbscript program that uses the DOM to remove nodes in an
> XML file. 
> I need to remove all the data between the two comment lines 

I'm surprised you haven't been snowed under with negative feedback, so 
I'll say politely "This is almost certainly a bad idea."  There is 
guaranteed to be no safe, portable way to do this, because the official 
XML specification specifically allows software to ignore comments.  The 
basis for this decision was to stop people doing what you're trying to do.

XML provides a lot of different ways to demarcate regions of your data 
for special processing (or no processing) - it seems that you ought to 
consider having <dotnet val="XXX"> ... and </dotnet> elements.

But if you *must* do this, given that you really can't use 
standards-compliant XML software to do this, and if you're really sure 
that the comment will always be together on a line as in your example, 
you could use a perl script with something like

my $suppress;
while (<>)
{
  if    (/<!-- Start [^\.]*\.net -->/) { $suppress = 1; }
  elsif (/<!-- End [^\.]*\.net -->/)   { $suppress = 0; }
  else { print unless $suppress; }
}

  -Tim





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS