halfbaked has asked for the wisdom of the Perl Monks concerning the following question:
<?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> <env:Body> <m:markupvalidationresponse env:encodingStyle="http://www.w3.org/2003/ +05/soap-encoding" xmlns:m="http://www.w3.org/2005/10/markup-validator +"> <m:uri>http://www.perlmonks.org/</m:uri> <m:checkedby>http://localhost/w3c-markup-validator/</m:checkedby> <m:doctype>-//W3C//DTD HTML 4.0 Transitional//EN</m:doctype> <m:charset>utf-8</m:charset> <m:validity>false</m:validity> <m:errors> <m:errorcount>59</m:errorcount> <m:errorlist> <m:error> <m:line>11</m:line> <m:col>66</m:col> + <m:message>document type does not allow element " +LINK" here</m:message> </m:error> <m:error> <m:line>14</m:line> <m:col>41</m:col> + <m:message>document type does not allow element " +LINK" here</m:message> </m:error> <m:error> <m:line>21</m:line> <m:col>4</m:col> + <m:message>document type does not allow element " +META" here</m:message> </m:error> </m:errorlist> </m:errors> <m:warnings> <m:warningcount>0</m:warningcount> <m:warninglist> <m:warning><m:message>No Character Encoding Found! Falling back to UTF-8. </m:message></m:warning> </m:warninglist> </m:warnings> </m:markupvalidationresponse> </env:Body> </env:Envelope>
my $ua = LWP::UserAgent->new(); my $response = $ua->request($request); my $parser = XML::LibXML->new(); my $doc = $parser->parse_string($response->content); Kube::Demonize::logmsg($response->content); #for (my $i = 0; $i < @errorlist; $i++) { # Kube::Demonize::logmsg(sprintf("%s\n", $errorlist[$i]->getEle +mentsByTagName('m:line')->textContent)); #} foreach my $d ($doc->getElementsByTagName('m:doctype')) { print $d->textContent; } foreach my $d ($doc->getElementsByTagName('m:validity')) { print $d->textContent; } foreach my $d ($doc->getElementsByTagName('m:charset')) { print $d->textContent; }
@errors[0] = %error( line=>120, col=>2, message=>'Tag not allowed'); @errors[1] = %error( line=>220, col=>3, message=>'Another error?');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Easiest way to parse a simple XML file?
by Tanktalus (Canon) on Dec 11, 2008 at 00:31 UTC | |
by halfbaked (Sexton) on Dec 12, 2008 at 02:06 UTC | |
|
Re: Easiest way to parse a simple XML file?
by ig (Vicar) on Dec 11, 2008 at 00:49 UTC | |
|
Re: Easiest way to parse a simple XML file?
by Anonymous Monk on Dec 11, 2008 at 10:08 UTC | |
|
Re: Easiest way to parse a simple XML file?
by Jenda (Abbot) on Dec 12, 2008 at 17:30 UTC |