AllExperts > Perl & CGI 
Search      
Perl & CGI
Volunteer
Answers to thousands of questions
 Home · More Perl & CGI Questions · Answer Library  · Encyclopedia ·
More Perl & CGI Answers
Question Library

Ask a question about Perl & CGI
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Justin Wheeler
Expertise
Any question relating to Perl including its internals, data structures, speed, memory usage, syntax, version changes, extra CPAN modules, code standards, code cleanup, or just silly problems.

Experience
I have been writing Perl code professionally for almost 10 years. I have modules on CPAN, have Perl code that's included in the latest versions of Redhat, Debian, etc. I have done professional Perl work for many household names including Ticketmaster, Interflora, and allbookstores.com.

Education/Credentials
Only work experience and a love of all things Perl.

 
   

You are here:  Experts > Computing/Technology > Perl/PHP > Perl & CGI > Perl XML:Simple

Perl & CGI - Perl XML:Simple


Expert: Justin Wheeler - 9/30/2009

Question
I'm trying to user xml:simple to break down an xml doc that I'm receiving from another website. I've been able to use xml:simple for other projects I have but this one I'm guessing is going to require a foreach statement. Im not 100% sure how to go about this.. An example of the xml file is below:
<outer>
     <xml>
  <undeveloped_lands>
     <land>
        <id>1</id>
        <image_url></image_url>
        <details></details>
        <num_owned></num_owned>
        <cost></cost>
        <name></name>
        <income></income>
     </land>
     <land>
        <id>2</id>
        <image_url></image_url>
        <details></details>
        <num_owned></num_owned>
        <cost></cost>
        <name></name>
        <income></income>
     </land>
     <land>
        <id>3</id>
        <image_url></image_url>
        <details></details>
        <num_owned></num_owned>
        <cost></cost>
        <name></name>
        <income></income>
     </land>
  </undeveloped_lands>
    </xml>
</outer>

I need to get each set of info and going to place them into different tables. How would I go about this?

Answer
Hi Matthew,

Yes, you'll likely need a foreach or something like that to traverse the data.

Your best bet is to XMLin() the file with XML::Simple, and then use Data::Dumper to Dumper() the data structure you get back.  Then, you'll clearly be able to figure out how to navigate the data.

Good luck,
Justin

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.