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 1:34PM messages near this date
view in the new Beta List Site
Re: XML::Twig beginner | Re: XML::Twig beginner
& XSLT Ying Liu schrieb:

>  I just started with XML::Twig. Lots of complicated xml files. I test some examples code bu
t didn't work well. There are too many methods in Twig. The following code is a simgple exam
ple. I want to get the text of <name>  (ThisIsMySequence) and two records of <ProcessName> (I
LikeProcesses, ILikeProcesses2). How to find levels of the xml file? and How to find interes
ting tags. Those XML files are quite long and complicated.
>  
>  Thanks,
>  Ying
>  

Welcome to the beautiful World of XML::Twig!
Maybe this will help to get you started:
__CODE__
#!/usr/bin/perl

use warnings;
use strict;

use XML::Twig;

my $xml = join "", <DATA> ;
my $twig = XML::Twig-> new(
    twig_handlers =>  {
        name =>  sub {
            print "Found a '<name> '-Tag, Value: ", $_->text, "\n";
        },
        processName =>  sub {
            print "Found a '<processName> '-Tag, Value: ", $_->text, "\n";
        },
    },
);
$twig-> parse($xml);
__DATA__
<?xml version="1.0"?> 
<SequenceConfig xmlns="com/hnc/core/common/process/sequence/config"> 
    <name> ThisIsMySequence</name>
    <VersionInfo> 
        <author> mbuser</author>
        <version> _working</version>
        <versionDescription> </versionDescription>
        <lastModifiedDate> 1150231914745</lastModifiedDate>
    </VersionInfo> 
    <ProcessNames> 
        <processName> ILikeProcesses</processName>
        <processName> ILikeProcesses2</processName>
    </ProcessNames> 
</SequenceConfig> 
__CODE_END__

Apart from reading `perldoc XML::Twig` over and over again ( it's worth
it IMHO ), the best advice I can offer is to go here
L<http://xmltwig.com/xmltwig/tutorial/index.html>  and work yourself
through it.

HTH,
Andreas Pürzer

-- 
perl -mAcme::JAPH

_______________________________________________
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