ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved