0

ねえ、私はこのタイプの XML を持っているので、データを取得しようとしています。これは、大きな XML コードのほんの一部です。

<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....

現在、次のようにすることで、公開更新の両方を問題なく取得できます。

<?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;
}
?>

ただし、親配列内から内部データを取得する方法については不明です-この場合はリンクです。

だから私は得る必要があります

リンク→href

私はそれが次のようになると想像します:

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

どんな助けでも素晴らしいでしょう!

4

2 に答える 2

0

simplexml_load_string次のようなコードでこれを行うことができます:

$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;
    }
}
于 2013-08-23T14:33:45.430 に答える
0

あなたが使用することができます:

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

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

もしあなたがhrefを取得したいのなら...あなたが何を望んでいるのか理解できたことを願っています:)

于 2013-08-23T14:22:29.803 に答える