note 84641 modified in domdocument.registernodeclass by danbrown
| From: | danbrown@php.net | Date: | Wed, 23 Jul 2008 15:58:07 +0000 |
| Subject: | note 84641 modified in domdocument.registernodeclass by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142616@lists.php.net to get a copy of this message | ||
If you want to get child nodes of some node, try something like this:
<?php
// check
$doc = new DomDocument();
// load XML file
$doc->loadXML($items);
// Now loop through and get root
// get those we need (all of them actually)
$Elements = $doc->getElementsByTagName("item");
// loop through
foreach($Elements as $elem)
{
// check if the element is a root one
if($elem->parentNode->getAttribute("link"))
{}
else
{
// if it IS then check if it has child nodes
if($elem->hasChildNodes())
{
// if it has them just got only child nodes
$Children = $elem->getElementsByTagName("item");
// do whatever you want with your children
}
}
}
?>
--was--
nobody at dontlikespam dot com-
Take it easy. When there is a bug you should not cry because there is always a way out of any
problem ;)
childNodes is really not a usefull thing. If you want to get child nodes of some node you'd
better use something like this:
// check
$doc = new DomDocument();
// load XML file
$doc->loadXML($items);
// Now loop through and get root
// get those we need (all of them actually)
$Elements = $doc->getElementsByTagName("item");
// loop through
foreach($Elements as $elem)
{
// check if the element is a root one
if($elem->parentNode->getAttribute("link"))
{}
else
{
// if it IS then check if it has child nodes
if($elem->hasChildNodes())
{
// if it has them just got only child nodes
$Children = $elem->getElementsByTagName("item");
// do whatever you want with your children
}
}
}
http://php.net/manual/en/domdocument.registernodeclass.php