SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple XML using php? Code provided

    Hi All,

    Using Simple XML I want to read this feed:

    http://www.slougheaz.org/xml2/feed_two.xml

    So I have this code to try and read the feed:

    PHP Code:
    <?php 
    $xmlstr 
    file_get_contents('feed_two.xml'); // read your file 

    $xml = new SimpleXMLElement($xmlstr); 

    echo 
    "Name: {$xml->venue_name}<br />"
    echo 
    "Description: {$xml->venue_description}<br />"
    echo 
    "Venue Address: {$xml->venue_address1}<br />"
    echo 
    "Town: {$xml->town}<br />"
    echo 
    "Country: {$xml->country}<br />"
    ?>
    To pick out the tags I want, but it does not do it? Will simple xml NOT be able to read this?

    Thanks

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because this xml has other structure. "$xml->venue[0]->venue_name;" does what you want. Try print_r($xml) to find out why.

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    I've tried that and it seems to print all the elements within the venue tag.

    http://www.slougheaz.org/xml2/smart.php

    I don't quite see how I can modify this to print only the fields I require though?

    Thanks

    Chris

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    print_r() is a debugging function. It doesn't do what you want, it tells you what you have to do. The output of print_r is

    Code:
    SimpleXMLElement Object
    (
        [venue] => SimpleXMLElement Object
            (
                [venue_id] => 9607
                [categories] => SimpleXMLElement Object
                    (
                        [category] => CLUBS
                    )
    
                [venue_name] => Reading Po Na Na
            )
    
    )
    It tells you that you need "$xml->venue->venue_name" to access "Reading Po Na Na" whatever that means.


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
  •