Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Parsing XML::Simple

by kevbot (Vicar)
on May 02, 2017 at 03:44 UTC ( [id://1189301]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-20 13:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found