in reply to Easiest way to parse a simple XML file?
My swiss-army-knife for XML is XML::Twig, which I used for this:
The output is:#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $t = XML::Twig->new(); $t->parsefile('x.xml'); my @errors = map { my %d = map { (my $tag = $_->tag()) =~ s/^m://; $tag => $_->text() } $_->children(); \%d } $t->get_xpath('//m:error'); use Data::Dumper; print Dumper \@errors;
You can do the same for warnings and whatever else you have. With some practice with the xpath, you can ensure that you're getting just what you want.$VAR1 = [ { 'col' => '66', 'message' => 'document type does not allow element "LINK" +here', 'line' => '11' }, { 'col' => '41', 'message' => 'document type does not allow element "LINK" +here', 'line' => '14' }, { 'col' => '4', 'message' => 'document type does not allow element "META" +here', 'line' => '21' } ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Easiest way to parse a simple XML file?
by halfbaked (Sexton) on Dec 12, 2008 at 02:06 UTC |