Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Parse multiple xml tags with different names to an array

by Anonymous Monk
on Sep 26, 2013 at 13:19 UTC ( #1055828=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Parse multiple xml tags with different names to an array
in thread Parse multiple xml tags with different names to an array

So you're after this?

my @nodeblocks = ( { CHILD1 => ["ABC"] }, { CHILD2 => ["KJLK"] }, { CHILD3 => ["NLLKJ"] }, );

#!/usr/bin/perl -- use strict; use warnings; use XML::LibXML 1.70; ## for load_html/load_xml/location use Data::Dump; my $xml=q{<ROOT_TAG> <CHILD1>ABC</CHILD1> <CHILD2>KJLK</CHILD2> <CHILD3>NLLKJ</CHILD3> </ROOT_TAG>}; my $dom = XML::LibXML->new( qw/ recover 2 / )->load_xml( string => $xml ); my @nodeboks; for my $kid ( $dom->findnodes(q{ //ROOT_TAG/* } ) ){ print $kid->nodePath, "\n"; push @nodeboks, { $kid->tagName => [ $kid->textContent ], }; } dd\@nodeboks; __END__ /ROOT_TAG/CHILD1 /ROOT_TAG/CHILD2 /ROOT_TAG/CHILD3 [ { CHILD1 => ["ABC"] }, { CHILD2 => ["KJLK"] }, { CHILD3 => ["NLLKJ"] }, ]

If your real problem is this short, this approach isn't too bad, but if its more comples, its not a substitute for what XML::Simple does for you, but XML::Rules is, its better than XML::Simple


Comment on Re^3: Parse multiple xml tags with different names to an array
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-09-22 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (191 votes), past polls