1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How can I read XML file..

Discussion in 'PHP & Perl' started by keval007, Jun 27, 2012.

  1. keval007

    keval007 Junior Member

    Joined:
    Jun 12, 2012
    Messages:
    145
    Likes Received:
    26
    Occupation:
    Web Scraper & PHP Developer
    I have attached one XML file which I want to read it in PHP. The file is to complex to understand, can any one give small code explanation to read this xml file.
     

    Attached Files:

  2. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    • Thanks Thanks x 1
  3. CodingAndStuff

    CodingAndStuff Regular Member

    Joined:
    May 6, 2012
    Messages:
    236
    Likes Received:
    84
    Occupation:
    Swagstronaut
    Location:
    You can't have my bots. Sorry :'(
    As jazzc noted, you could use SimpleXML or any of the other XML parsing libraries available on php.net.

    Personally I like to use the Simple HTML DOM parser (which is available on sourceforge) to traverse the DOM/XML trees and spit out data. The class is tiny and useful.

    What you will need to do (assuming you need to access the data within the curr_custs_aff block) is navigate to <root>, then <curr_custs_aff>, and finally <areas>. Once you are there you're going to have to select the children of <areas> and make sure they're after the area_name that you want to pull data from. It would be much easier if the XML was, well, valid I guess. It's kind of all over the place to be honest. This is honestly one of the main reasons I wish everyone would switch to a json standard =[.

    Hope I helped!
     
    • Thanks Thanks x 2
    Last edited: Jun 28, 2012
  4. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    +1 !