Example #1
3
File: Rss.php Project: hisaboh/w2t
 /**
  * xmlをRssに変換する
  *
  * @param string $src
  * @return Rss
  */
 public static function parse($src)
 {
     if (Tag::setof($rss, $src, "rss")) {
         $result = new self();
         $result->version($rss->inParam("version", "2.0"));
         if (Tag::setof($channel, $rss->value(), "channel")) {
             $result->title($channel->f("title.value()"));
             $result->link($channel->f("link.value()"));
             $result->description($channel->f("description.value()"));
             $result->language($channel->f("language.value()"));
             $result->copyright($channel->f("copyright.value()"));
             $result->docs($channel->f("docs.value()"));
             $result->managingEditor($channel->f("managingEditor.value()"));
             $result->webMaster($channel->f("webMaster.value()"));
             $result->lastBuildDate($channel->f("lastBuildDate.value()"));
             $result->pubDate($channel->f("pubDate.value()"));
             $value = $channel->value();
             $result->item = RssItem::parse($value);
             return $result;
         }
     }
     throw new Exception("no rss");
     /***
     			 $src = text('
     						<rss version="2.0">
     							<channel>
     								<title>rhaco</title>
     								<link>http://rhaco.org</link>
     								<description>php</description>
     								<language>ja</language>
     								<copyright>rhaco.org</copyright>
     								<docs>hogehoge</docs>
     								<lastBuildDate>2007-10-10T10:10:10+09:00</lastBuildDate>
     								<managingEditor>tokushima</managingEditor>
     								<pubDate>2007-10-10T10:10:10+09:00</pubDate>
     								<webMaster>kazutaka</webMaster>
     								<item>
     									<title>rhaco</title>
     									<link>http://rhaco.org</link>
     									<description>rhaco desc</description>
     								</item>
     								<item>
     									<title>everes</title>
     									<link>http://www.everes.net</link>
     									<description>everes desc</description>
     								</item>
     							</channel>
     						</rss>
     					');
     					$xml = Rss::parse($src);
     					eq("2.0",$xml->version());
     					eq("rhaco",$xml->title());
     					eq("http://rhaco.org",$xml->link());
     					eq("php",$xml->description());
     					eq("ja",$xml->language());
     					eq("rhaco.org",$xml->copyright());
     					eq("hogehoge",$xml->docs());
     					eq(1191978610,$xml->lastBuildDate());
     					eq("Wed, 10 Oct 2007 10:10:10 +0900",$xml->fmLastBuildDate());
     					eq("tokushima",$xml->managingEditor());
     					eq(1191978610,$xml->pubDate());
     					eq("Wed, 10 Oct 2007 10:10:10 +0900",$xml->fmPubDate());
     					eq("kazutaka",$xml->webMaster());
     					eq(2,sizeof($xml->item()));
     			*/
 }