SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML parsing - Same named elements

    Lets say I have an XML file like this that needs to be parsed:

    Code:
    <menu>
       <item>
          <name>Home</name>  
          <name>About Us</name>  
          <name>Products</name> 
             <menu>
                <item>
                   <name>Desktops</name>
                   <name>Hard Drives</name>
                </item>
             </menu>
          <name>Contact Us</name>  
       <item>
    </menu>
    I know parsers put the elements into an array like $_array['element'] = value. How am to distinguish between the parent menu element and child menu element?

  2. #2
    SitePoint Zealot bobber205's Avatar
    Join Date
    Sep 2006
    Location
    Oregon
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First I would retrive the menu item, then, using the same method, retrieve the item. After that retrieve the second menu item.

    Once you have an object that represents the second menu item, dig into that.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone recommend a good class to do this? I'm using PHP 4.

  4. #4
    SitePoint Zealot bobber205's Avatar
    Join Date
    Sep 2006
    Location
    Oregon
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would use this.


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
  •