Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hey all i have this type of XML i am trying to get data from. This is just a snip of the large XML code:

<entry>
  <id>http://www.google.com/calendar/feeds/[Letters/numbers here]group.calendar.google.com/public/basic/[Letters/numbers here]</id>
  <published>2013-08-01T13:40:24.000Z</published>
  <updated>2013-08-01T13:40:24.000Z</updated>
  <title type='html'>[Title Here]</title>
  <summary type='html'>When: Tue Sep 24, 2013 7am</summary>
  <content type='html'>When: Tue Sep 24, 2013 7am
        &lt;br /&gt;Event Status: confirmed
  </content>
  <link rel='alternate' type='text/html' href='https://www.google.com/calendar/event?eid=[Letters/numbers here]' title='alternate'/>
  <link rel='self' type='application/atom+xml' href='https://www.google.com/calendar/feeds/[Letters/numbers here]group.calendar.google.com/public/basic/[Letters/numbers here]'/>
  <author>
    <name>[email here]</name>
    <email>[email here]</email>
  </author>     
</entry>

   etc... etc....

Currently i can get both published and updated just fine by doing the following:

<?php
$url = strtolower($_GET['url']);
$doc = new DOMDocument(); 
$doc->load('http://www.google.com/calendar/feeds/[number/letters here].calendar.google.com/public/basic');
$entries = $doc->getElementsByTagName("entry");

foreach ($entries as $entry) { 
  $tmpPublished = $entry->getElementsByTagName("published"); 
  $published = $tmpPublished->item(0)->nodeValue;

  $tmpUpdated = $entry->getElementsByTagName("updated"); 
  $updated = $tmpUpdated->item(0)->nodeValue;
}
?>

However i am unsure as to how to get the inner data from within the parent array - that being link in this case.

So i need to get

link->href

I would imagine it would be:

$tmpLink = $entry->getElementsByTagName("link"); 
$link = $tmpLink->item( 2 )->nodeValue;

Any help would be great!

share|improve this question
    
have you thought about using xpath? relevant SO question and answer –  miah Aug 23 '13 at 14:24

2 Answers 2

you can use:

$links = $doc->getElementsByTagName("link");

foreach ($links as $link) { 
  $href = $link->getAttribute("href");
}

if you want to get href... hope that I understood what you wanted :)

share|improve this answer

You can do this with simplexml_load_string like following codes:

$entries = simplexml_load_string($string);

foreach ($entries as $entry) { 

    echo $entry->published;
    echo $entry->updated;  

    foreach($entry->link as $link)
    {
        echo $link->attributes()->type;
        echo $link->attributes()->rel;
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.