XML::Twig question

Hi,

Trying this but only "aaa" outputs not "bbb". What's fix? I'm new to
XML and Perl - help appreciated.

xml file:

<?xml version='1.0'?>
<config>
<attrbs>
<attrb>aaa</attrb>
<attrb>bbb</attrb>
</attrbs>
</config>


perl file:

#!/usr/bin/perl -w
use strict;
use XML::Twig;

my $twig= XML::Twig->new( twig_roots => {'/config/attrbs' =>
\&do_attrb});
$twig->parsefile( "xmlt1.xml");
$twig->purge();

sub do_attrb {
my($a1) = $_->find_nodes("attrb");
print $a1->text, "\n";
}


output:

aaa
goldtech [ So, 23 Dezember 2007 20:25 ] [ ID #1893104 ]

Re: XML::Twig question

On Dec 23, 2:25 pm, goldtech <goldt... [at] worldpost.com> wrote:

> my($a1) = $_->find_nodes("attrb");
> print $a1->text, "\n";

find_nodes returns a list of nodes, so the first line here
assigns the first element of that list to $a1.

I think you want
my [at] attrb= _->find_nodes("attrb");
print map { $_->text } [at] attrb;

Does that help?

--
mirod
mirod [ Mo, 24 Dezember 2007 12:34 ] [ ID #1893457 ]

Re: XML::Twig question

....snip...
>
> I think you want
> my [at] attrb= $_->find_nodes("attrb");
> print map { $_->text } [at] attrb;
>
> Does that help?
>

Perfect - Thank you.
goldtech [ Mo, 24 Dezember 2007 22:41 ] [ ID #1893464 ]
Perl » comp.lang.perl.modules » XML::Twig question

Vorheriges Thema: problem in telnet using perl
Nächstes Thema: Is a hash the best method to do this?