Quantcast
Channel: PHP: How to detect/parse all TAGS in rss/feed XML? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by gion_13 for PHP: How to detect/parse all TAGS in rss/feed XML?

$
0
0

You can access each node recursively and you can choose from which one to get your data by checking if the tag name matches your desired one :

$indent = 0;
$tab = 4;
function indent($indent){
    $r = "";
    for($i=0;$i<$indent;$i++)
        $r .= " ";
    return $r;
}
function parseNode($node){
    global $indent,$tab;
    if(!$node->hasChildNodes())
        return;
    $indent += $tab;
    // if($note->tagName == "item") do something special
    echo indent($indent)."<".$note->nodeName.">";
    foreach ($node->childNodes as $c) 
        parseNode($c);

    echo indent($indent)."</".$note->nodeName.">";
    $indent -= $tab;
}
$xmlDoc = new DOMDocument();
$xmlDoc->load($url);
parseNode($xmlDoc);

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>