Here are two quick and dirty functions that use SimpleXML to detect if a feed xml is RSS or ATOM:
function is_rss($feedxml) {
@$feed = new SimpleXMLElement($feedxml);
if ($feed->channel->item) {
return true;
} else {
return false;
}
}
function is_atom($feedxml) {
@$feed = new SimpleXMLElement($feedxml);
if ($feed->entry) {
return true;
} else {
return false;
}
}
The functions take in the full text feed (retrieved via cURL, for example) and return a true or a false based on the result.
SimpleXML
- 導入
- インストール/設定
- 定義済み定数
- 例
- SimpleXML 関数
- SimpleXMLElement->addAttribute() — SimpleXML 要素に属性を追加する
- SimpleXMLElement->addChild() — XML ノードに子要素を追加する
- SimpleXMLElement->asXML() — SimpleXML 要素に基づき整形式の XML 文字列を返す
- SimpleXMLElement->attributes() — 要素の属性を定義する
- SimpleXMLElement->children() — 指定したノードの子ノードを見付ける
- SimpleXMLElement->__construct() — 新しい SimpleXMLElement オブジェクトを作成する
- SimpleXMLElement->getDocNamespaces() — ドキュメントで宣言されている名前空間を返す
- SimpleXMLElement->getName() — XML 要素の名前を取得する
- SimpleXMLElement->getNamespaces() — ドキュメントで使用している名前空間を返す
- SimpleXMLElement->registerXPathNamespace() — 次の XPath クエリ用の prefix/ns コンテキストを作成する
- SimpleXMLElement->xpath() — XML データに Xpath クエリを実行する
- simplexml_import_dom — DOM ノードから SimpleXMLElement オブジェクトを取得する
- simplexml_load_file — XMLファイルをパースし、オブジェクトに代入する
- simplexml_load_string — XML 文字列をオブジェクトに代入する
SimpleXML
aalaap at gmail dot com
30-Jun-2008 06:58
30-Jun-2008 06:58
