xml - Only select nodes without a namespace/prefix in PHP DOM? -
i'm trying read rss feeds dom in php one:
<channel> <atom:link href='' rel='self' type='application/rss+xml' /> <title>techstuff</title> <link>http://www.howstuffworks.com</link> to grab link (<link></link>) use piece of code:
$doc->getelementsbytagname('link')->item(0); it works in other rss feeds have tried. 1 has placed <atom:link> before <link>, means grabs <atom:link> instead.
so how do select nodes without namespace?
you can tell whether node has namespace checking ->prefix or ->namespaceuri:
foreach ($doc->getelementsbytagname('link') $link) { if (strlen($link->prefix)) { continue; } // $link not have prefix }
Comments
Post a Comment