in reply to Re: parsing xml
in thread parsing xml

To filter out parts of the XML, I usually use a combination of twig_roots on the bits I want to skip, and twig_print_outside_roots to output the rest of the input.

The only problem with this is that if the XML is indented the way the example is, it leaves empty lines where the discarded part was. I'll have to figure something out to deal with this.

#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $xmlstr = <<EOF; <top> <COMPLETE> <T>test</T> <L>light</L> <INFO>information</INFO> </COMPLETE> <COMPLETE> <T>test</T> <L>light</L> <INFO>informa</INFO> </COMPLETE> </top> EOF my $twig = XML::Twig->new( twig_roots => {INFO => 1}, twig_print_outside_roots => 1, ); $twig->parse($xmlstr); __END__ <top> <COMPLETE> <T>test</T> <L>light</L> </COMPLETE> <COMPLETE> <T>test</T> <L>light</L> </COMPLETE> </top>