Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Parsing XML with XML::Simple

by Preceptor (Deacon)
on Jul 05, 2016 at 09:22 UTC ( [id://1167214]=note: print w/replies, xml ) Need Help??


in reply to Parsing XML with XML::Simple

I would refer you to this, on the problems with XML::Simple: Why is XML::Simple "discouraged"

I would strongly suggest looking at XML::Twig instead - as an easy-to-use XML parser, that _actually_ does XML, and not some nasty hack job. If you do, your code becomes something like this:

#!/usr/bin/env perl use strict; use warnings; use XML::Twig; my $twig = XML::Twig->new->parsefile('ciao.tmex'); foreach my $entry ( $twig->get_xpath('//Entry') ) { print "My terms: ", $entry->get_xpath('./German/Term',0)->text, " - ", $entry->get_xpath('./Italian/Term',0)->text, "\n"; }

You can, if you prefer, also use "first_child" and "children" to navigate the XML:

foreach my $entry ( $twig->root->children('Entry') ) { print "My terms: ", $entry->first_child('German')->first_child_text('Term'), " - ", $entry->first_child('Italian')->first_child_text('Term'), "\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2026-02-12 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.