in reply to Easiest way to parse a simple XML file?
use strict; use XML::Rules; my $parser = XML::Rules->new( stripspaces => 7, namespaces => { 'http://www.w3.org/2005/10/markup-validator' => '', 'http://www.w3.org/2003/05/soap-envelope' => 'env', }, start_rules => { warnings => 'skip', }, rules => { _default => 'content', error => 'as array no content', errorlist => 'no content', errors => sub { return errors => $_[1]->{errorlist}{error}}, warning => sub {return warning => $_[1]->{message}}, 'markupvalidationresponse' => 'no content', 'env:Body' => 'as is', 'env:Envelope' => sub {return $_[1]->{'env:Body'}{markupvalida +tionresponse}}, } ); my $data = $parser->parse(\*DATA); use Data::Dumper; print Dumper($data); __DATA__ <?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> ...
XML::Rules lets you tweak and trim the structure produced by parsing the XML so that you end up with only the stuff you need in a format that's most convenient to you.
|
|---|