Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

XML::Simple - how to select keys while parsing?

by hparashu (Initiate)
on Oct 09, 2013 at 16:40 UTC ( [id://1057586]=perlquestion: print w/replies, xml ) Need Help??

hparashu has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am using XML::Simple to parse the contents of an XML file. While parsing like this -

 my $ref = XMLin([<xml file or string>] [, <options>]);

how do i pick only keys of my interest & not all keys in XML file to get into hashref?

Replies are listed 'Best First'.
Re: XML::Simple - how to select keys while parsing?
by daxim (Curate) on Oct 09, 2013 at 16:49 UTC
Re: XML::Simple - how to select keys while parsing?
by Jenda (Abbot) on Oct 09, 2013 at 17:52 UTC

    You want XML::Rules. See the docs and the posts here.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

Re: XML::Simple - how to select keys while parsing?
by talexb (Chancellor) on Oct 09, 2013 at 16:52 UTC

      It apparently makes about as much sense as deprecating plastic child knife for a chain saw. You can cut bread with it, somehow, but experience with the knife will be of no use to you.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

Re: XML::Simple - how to select keys while parsing?
by AlexTape (Monk) on Oct 09, 2013 at 16:52 UTC
    you have to give XML::Twig a try.
    maybe thats what you are looking for..

    IMHO itīs not possible to do it with XML::Simple
    $perlig =~ s/pec/cep/g if 'errors expected';
Re: XML::Simple - how to select keys while parsing?
by Bloodnok (Vicar) on Oct 10, 2013 at 09:42 UTC
    As has been said elsewhere, I don't believe that you can do it as an atomic operation with XML::Simple, but I believe that you could maybe do it in 2 stages e.g. something along the lines of ...
    my $ref = XMLin(<file); my $keys_you_dont_want_re = 'key1|key2|key3|...'; $ref = { map { $ref->{$_} } grep !/^($keys_you_dont_want_re)$/, keys % +$ref };
    Just a, not especially well considered, thought ...

    A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1057586]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found