Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: language selection via libxml (perlquote)

by Anonymous Monk
on Jan 20, 2014 at 09:53 UTC ( [id://1071289]=note: print w/replies, xml ) Need Help??


in reply to language selection via libxml

If you add use diagnostics; it will print a more verbose error message explaining this scenario (there is no variabele @ID which you keyboarded into your string)

string quoting/interpolation are explained in perlintro and Strings in Perl: quoted, interpolated and escaped

You can simplify your xpaths, like this (untested , may contain typos)

sub enumerate_languages { my( $xmltree ) = @_; my @nodes = $xmltree->findnodes( '/language' ); my @langs = map { $_->tagName } @nodes; return @langs; } sub get_language { my( $xmltree, $lang ) = @_; my @nodes = $xmltree->findnodes( "/language/$lang/*" ); my %pairs ; for my $node ( @nodes ){ $pairs{ $node->getAttribute('ID') } = $node->textContent; } return %pairs; }

FWIW, traditionally this is done using .po/.mo files, each language gets its own file ... gettext.. and all that ... :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-25 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found