php解析后访问xml对象


access xml object after php parse

HI有人能解释一下如何访问这个xml提要的"item"部分吗。这是文件的VAR_DUMP。我使用simplexml_load_string从谷歌中提取提要,但我如何访问"项目"内容

    object(SimpleXMLElement)[1]
  public '@attributes' => 
    array
      'version' => string '2.0' (length=3)
  public 'channel' => 
    object(SimpleXMLElement)[2]
      public 'generator' => string 'NFE/1.0' (length=7)
      public 'title' => string 'running barefoot - Google News' (length=30)
      public 'link' => string 'http://news.google.com/news?pz=1&ned=us&hl=en&q=running+barefoot' (length=64)
      public 'language' => string 'en' (length=2)
      public 'webMaster' => string 'news-feedback@google.com' (length=24)
      public 'copyright' => string '©2012 Google' (length=17)
      public 'pubDate' => string 'Sun, 22 Jan 2012 04:38:34 GMT' (length=29)
      public 'lastBuildDate' => string 'Sun, 22 Jan 2012 04:38:34 GMT' (length=29)
      public 'image' => 
        object(SimpleXMLElement)[3]
          public 'title' => string 'running barefoot - Google News' (length=30)
          public 'url' => string 'http://www.gstatic.com/news/img/logo/en_us/news.gif' (length=51)
          public 'link' => string 'http://news.google.com/news?pz=1&ned=us&hl=en&q=running+barefoot' (length=64)
      public 'item' => 
        array
          0 => 
            object(SimpleXMLElement)[4]
              ...
          1 => 
            object(SimpleXMLElement)[5]
              ...
          2 => 
            object(SimpleXMLElement)[6]
              ...
          3 => 
            object(SimpleXMLElement)[7]
              ...
          4 => 
            object(SimpleXMLElement)[8]
              ...
          5 => 
            object(SimpleXMLElement)[9]
              ...
          6 => 
            object(SimpleXMLElement)[10]
              ...
          7 => 
            object(SimpleXMLElement)[11]
              ...
          8 => 
            object(SimpleXMLElement)[12]
              ...
          9 => 
            object(SimpleXMLElement)[13]
              ...
      public 'description' => string 'Google News' (length=11)

看起来您可以访问'item'成员变量,如下所示:$yourObject->channel->item

在询问之前是否尝试过搜索?有很多关于如何解析RSS提要的教程,例如

foreach($yourObject->channel->item as $item)
{
  echo $item->title;
  echo $item->link;
}