Results 1 to 2 of 2

Thread: SimpleXML and Google Calendar

  1. #1
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default SimpleXML and Google Calendar

    Hello all,

    I'm very new to SimpleXML and I'm learning how to do parsing XML data. I've got a code bit that I'm trying to use to pull Google Calendar data and display it on a site. I don't need anything more than something to pull the data and display it. Below is the code that I'm using:

    PHP Code:
    <?php
        $userid 
    'username%40googlemail.com';
        
    $magicCookie 'cookie';
        
        
    // build feed URL
        
    $feedURL "http://www.google.com/calendar/feeds/USERNAMEREMOVED/public/basic";
        
        
    // read feed into SimpleXML object
        
    $sxml simplexml_load_file($feedURL);
        
        
    // get number of events
        
    $counts $sxml->children('http://a9.com/-/spec/opensearchrss/1.0/');
        
    $total $counts->totalResults
        
    ?>
        <h1><?php echo $sxml->title?></h1>
        <?php echo $total?> event(s) found.
        <p/>
        <ol>
        <?php    
        
    // iterate over entries in category
        // print each entry's details
        
    foreach ($sxml->entry as $entry) {
          
    $title stripslashes($entry->title);
          
    $summary stripslashes($entry->summary);
          
    $link stripslashes($entry->id);
          
          echo 
    "<li>\n";
          echo 
    "<h2>$title</h2>\n";
          echo 
    "$summary <br/>\n";
          echo 
    "$link <br/>\n";
          echo 
    "</li>\n";
        }
        
    ?>
    What I need is to display the link back to the Google Calendar event when clicked. The problem is I don't know how to tell the SimpleXML to use the link in XML data tagged: <link rel="alternate" .....>. There is also a <link rel="self"....> in the code, so adding "$link = stripslashes($entry->link); doesn't work. If anyone can tell me the code I need to use, I would appreciate it. Thanks

  2. #2
    Join Date
    Sep 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    nest this within the foreach statement that you have already....

    foreach ($entry->link as $link){
    if($link['rel']=='alternate'){
    echo "<h2><a href='" .$link['href'] . "'>" . $entry->title . "</a></h2>";
    }
    }

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
  •