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 |