Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: That's not a simple parser

by karlgoethebier (Abbot)
on Feb 01, 2015 at 13:07 UTC ( [id://1115216]=note: print w/replies, xml ) Need Help??


in reply to That's not a simple parser
in thread XML::Parser Tutorial

Please see also XML::LibXML::Simple for a handy replacement for XML::Simple:

#!/usr/bin/env perl use warnings; use strict; use Data::Dump; use XML::LibXML::Simple qw(XMLin); $/ = undef; my $xml = <DATA>; my $ref = XMLin $xml; # dd $ref; foreach my $msg (@{$ref->{'message'}}) { my $h = substr($msg->{'time'}, 8, 2); my $n = substr($msg->{'time'}, 10, 2); my $author = $msg->{'content'} =~ s/^\/me// ? $msg->{'author'} : " +<$msg->{'author'}>"; print "$h:$n $author: $msg->{'content'}\n"; } __END__ <CHATTER><INFO site="http://perlmonks.org" sitename="Perl Monks">Rende +red by the Chatterbox XML Ticker</INFO><message author="OeufMayo" tim +e="20010228112952">test</message><message author="deprecated" time="2 +0010228113142">pong</message><message author="OeufMayo" time="2001022 +8113153">/me test again; :)</message><message author="OeufMayo" time= +"20010228113255">&lt;a href="#"&gt;please note the use of HTML tags&l +t;/a&gt;</message></CHATTER>

Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Replies are listed 'Best First'.
Re^2: That's not a simple parser
by Anonymous Monk on Feb 02, 2015 at 08:16 UTC

    Please see also XML::LibXML::Simple for a handy replacement for XML::Simple:

    :) nope, XML::Rules is a handy replacement for XML::Simple

      Sure yes, from the view of Jenda ;-)

      BTW, i didn't know XML::Rules, thank you for the hint.

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1115216]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-29 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found