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"; }
|
|---|