in reply to Parsing XML::Simple

Hello Anonymous Monk,

The documentation for XML::Simple states that it should not be used in new code (see the STATUS OF THIS MODULE section). The author recommends alternatives such as XML::LibXML or XML::Twig. Perl XML::LibXML by Example looks like a good resource for getting started with XML::LibXML. Using information that I found there, I put together this example:

#!/usr/bin/env perl use strict; use warnings; use v5.10; use XML::LibXML; my $file = 'myxml.xml'; my $dom = XML::LibXML->load_xml(location => $file); foreach my $lang_set ($dom->findnodes('/DB/termEntry/langSet')) { my $lang = $lang_set->getAttribute('xml:lang'); foreach my $term_grp ($lang_set->findnodes('./termGrp')){ say '$lang : '. $term_grp->findvalue('./term'); } } exit;
I hope you find this helpful.

Replies are listed 'Best First'.
Re^2: Parsing XML::Simple
by Anonymous Monk on May 02, 2017 at 07:07 UTC

    Thank you!

Re^2: Parsing XML::Simple
by Anonymous Monk on May 04, 2017 at 13:10 UTC

    After trying for hours to adapt the other proposals to a slighty different XML input without success I started with XML::LibXML and this example... and I can say it was much much easier to adapt! Nice module, thank you!