Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: XML processing

by Tanktalus (Canon)
on Aug 06, 2005 at 02:44 UTC ( #481427=note: print w/replies, xml ) Need Help??

in reply to XML processing

Seconding borisz's advice, here's some (untested) XML::Twig code to do this, in case you want to continue doing stuff with the results in perl:

use XML::Twig; # ... my $twig = XML::Twig->new(); $twig->parsefile($XmlFile); my @a_elements = $twig->get_xpath("//a"); foreach my $el (@a_elements) { my $text = $el->text(); # do stuff with $text. }
It's actually pretty easy, once you know which APIs you want ;-)

Update: Changed loop variable from $a to $el when reminded by graff. Tks.

Replies are listed 'Best First'.
Re^2: XML processing
by graff (Chancellor) on Aug 06, 2005 at 16:24 UTC
    But it would be better not to use "$a" as the name of the iterator variable in the "for" loop, in case "doing stuff" includes using "sort".
Re^2: XML processing
by shreya (Novice) on Aug 10, 2005 at 22:31 UTC

      something like $ElementA .= $element->sprint;?

      Thanks Mirod. This worked. I am still trying to get used to this response method. Didnt realise that someone replied ot my old posts. Wish there was a way to notify by email when someone replies to your posts. Later
        In your User Settings you can turn on "msg me when there's a reply to one of my posts".

        (update: Of course, this post might be pointless if you don't check old posts)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://481427]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2020-05-25 04:38 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (143 votes). Check out past polls.