Re: XML::Twig beginner
by Andreas P?rzer other posts by this author
Jun 19 2006 11:17PM messages near this date
view in the new Beta List Site
Re: XML::Twig beginner
|
Re: XML::Twig beginner
& XSLT Ying Liu schrieb:
> By the following code, I can get the
>
> my $xml_twig = XML::Twig->new(); # create the twig
> $xml_twig->parsefile('test.x');
> my $results = $xml_twig->root;
Bad Variable-naming IMHO. $results has nothing to do with your expected
results, by convention this is called $root because it's the
startingpoint for all further actions (think of it as:
the-whole-xml-document).
> my $seq_name = $results->field('name');
my $seq_name = $results-> field();
<Quote from the docs:>
field ($optional_condition)
Same method as "first_child_text" with a different name
</Quote from the docs:>
So, field() will give you the text of $root's first-child, which happens
to be the <name> tag.
>
> How can I get the info under 'ProcessName'? field() does not work. Anyone can help?
>
TIMTOWTDI, as always.
One Way:
my $first_process = $twig-> first_elt('processName');
print $_-> text, "\n" for
( $first_process, $first_process-> next_sibling );
Another Way:
my @processes = $root-> children('ProcessNames');
for ( @processes ) {
print $_-> text, "\n" for $_->children;
}
Yet Another Way:
my @names = $root-> descendants('processName');
print $_-> text, "\n" for @names;
> Thanks,
> Ying
>
>
HTH,
Andreas Pürzer
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Ying Liu
Ying Liu
Andreas P?rzer
Ying Liu
Andreas Pürzer
Ying Liu
Andreas Pürzer
Andreas Pürzer
Ying Liu
|