perlmonks_user has asked for the wisdom of the Perl Monks concerning the following question:

I am using xmlin function of XML::Simple to parse XML data file. However, it reads the XML comments which i would like to ignore. How can this be accomplished. I think this can be done using XML::Twig but i would like to use XML::Simple

Here is a snippet of my code.

$xmlObj = new XML::Simple (KeyAttr=>[], SuppressEmpty => 1); my $xmlFileKeyAttr = eval { $xmlObj->XMLin($file) };
Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: How to ignore XML comments using XML::Simple
by toolic (Bishop) on Nov 16, 2011 at 22:02 UTC
    XML::Simple seems to ignore comments.
    use warnings; use strict; use XML::Simple; use Data::Dumper; my $xml = ' <foo> <bar>123</bar> <!-- COMMENT --> <bar>abc</bar> </foo> '; my $ref = XMLin($xml); print Dumper($ref); __END__ $VAR1 = { 'bar' => [ '123', 'abc' ] };
    Please show a small snippet of your XML file and the contents of your $xmlFileKeyAttr (both with comments).