From: "Beginner" <[EMAIL PROTECTED]> > Hi All (and a happy holiday to those that will get a break), > > I am trying to read in an XML file of addresses. I need to remove all > the address data from the file where code =~ /^000/ (there are none in > the example data below). I need to reproduce that data 'as is', so I > need to honour the tag structure, although the order of the tags > doesn't need to be honoured. > > I have been trying to use XML::Simple and I had a go with XML::Smart > but I haven't been able to get the results I want. > > =========== The data file =========== > <?xml version = "1.0" encoding= "utf-8"?> > <addresses> > <address number="2577"> > <code>BJPPHO00</code> > <record_type>client</record_type> > <address_type>shipping</address_type> > <Postcode>EC1Y 4RX</Postcode> > <Country>GBR</Country> > <lines> > <line>PIGEON MEDIA</line> > <line>HAYMARKET HOUSE</line> > <line>28-29 HAYMARKET</line> > <line>LONDON</line> > <lines>EC1Y 4RX</line> > </lines> > </address> > <address number="2578"> > <code>BJPUBL00</code> > <record_type>client</record_type> > <address_type>shipping</address_type> > <Postcode>SU1V 0AQ</Postcode> > <Country>GBR</Country> > <lines> > <line>RIVER HOUSE</line> > <line>12-14 BERRY STREET</line> > <line>SURREY</line> > <line>SU1V 0AQ</line> > </lines> > </address> > </addresses> > =============================
Another options is: use XML::Rules; my $parser = XML::Rules->new( style => 'filter', rules => [ _default => 'raw', # keep as much details (order, whitespace) as possible code => 'raw extended', # keep the details, but also make the data easier # to access while handling the <address> tag address => sub { my $code = $_[1]->{':code'}{_content}; if ($code =~ /^000/) { return; } else { return $_[0] => $_[1]; } }, ], ); $parser->filterfile($xmlfile, \*STDOUT); __END__ HTH, Jenda P.S.: Please use the just uploaded 0.13, not the 0.09. There was a bug in escaping the data written to the XML while filtering. ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/