Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

XML::Parser Help!

by Anonymous Monk
on May 06, 2010 at 20:09 UTC ( [id://838791]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks, I am parsing a XML file and instead of getting the value of this variable I am getting the representation of the hash, What I am doing wrong, I can't see it anymore, here is a sample code of where the issue is:
my $get_phone=""; if (ref($xml_data->{'mainA'}->{'mainB'}->{'mainC'}) eq 'ARRAY') { $get_phone = $xml_data->{'mainA'}->{'mainB'}->{'mainC'}->[0]; } else { $get_phone = $xml_data->{'mainA'}->{'mainB'}->{'mainC'}; } $got_phone = $get_phone->{'mainD'}->{'mainE'}->{'mainF'}->{'mainG' +}; print "<br>**$got_phone**<br>"; # I am getting this Result: **HASH(0xa8f8064)**

Thanks for the help!

Replies are listed 'Best First'.
Re: XML::Parser Help!
by runrig (Abbot) on May 06, 2010 at 20:26 UTC
    I'm assuming you're using XML::Simple. Look at the ForceArray option so that you done have to check whether a node gets turned into an arrayref or hashref. It might be easier to just use XML::LibXML directly if the document is not too large, or XML::Twig or XML::Rules if it is large.

    That being said, what you have left is a hashref, so you need to dereference it further to get your desired results. You can use Data::Dumper to see what further dereferencing needs to be done on the variable. If you had actual runnable sample code, this would be easier to debug.

      I'm assuming you're using XML::Simple.
      Unlikely, because the subject line refers to XML::Parser. But otherwise, your suggestions - in particular the idea to use Data::Dumper, are of course correct.

      -- 
      Ronald Fischer <ynnor@mm.st>

        XML::Parser itself would not produce a data structure similar to the one accessed in the code example. Even though it can produce a data structure out of the XML, it would look very different.

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found