SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Michigan
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parsing XML with PHP Question (Simple Question)

    I'm pretty good at HTML and all, but I have a PHP script that I made awhile ago and I need to update it.

    What I don't know how to do is to parse XML data that is several "branches" in..meaning something that is located at...

    <Categories>
    <Items>
    <Offers>
    <Offer>
    Data.....
    </Offer>
    </Offers>
    </Items>
    </Categories>

    I'm only use to XML data that is all on one "branch" so I don't know what to do. In my current script, I use something like this '.$node_array[$i]["OFFER"].' to display data from the XML file, but that doesn't take into account the more complex hierarchy.

    What do I have to do to format the .$node_array........ to make it read the complex hierarchy as I described above...for example the data in the "Offer" area above?

    Hope I explained that clearly enough...any help is appreciated. Thanks

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Have you looked at the simplexml_load_file function?
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Michigan
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    Have you looked at the simplexml_load_file function?
    How would I use that? Thanks again for the reply.

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    PHP Code:
    $xml simplexml_read_file('/some/file.xml');

    foreach(
    $xml->Categories as $cat)
    {
      foreach(
    $cat->Offers as $off)
      {
         Print 
    'The offer is '.$off->Offer;
       }

    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •