Home >Backend Development >PHP Tutorial >小妹又遇到取XML子节点有关问题。请帮忙给看看1

小妹又遇到取XML子节点有关问题。请帮忙给看看1

WBOY
WBOYOriginal
2016-06-13 10:13:301173browse

小妹又遇到取XML子节点问题。请帮忙给看看1
我取到一级目录的节点,但是它的下一级目录我就是取不到

不知道为什么请各位师哥指正。
$XMLStr='

 
 
 
 
 

 
 
 
 

 

';
if($XMLStr!="")
{
$XMLStr=stripcslashes($XMLStr);
$xml = new DOMDocument(); //建立一个DOMDocument
$xml->loadXML($XMLStr); //Php指定需要读取xml文件的位置
$itemObj = $xml->getElementsByTagName('WallPaper');//按照名称取得节点,返回所有节点的集合,不过这里这样读LevelOne是没有意义的....

for($i=0;$ilength;$i++)
{  
$id= $itemObj->item($i)->getAttribute("ID");
$updatetime= $itemObj->item($i)->getAttribute("UpdateTime");
echo "ID:".$id."
";
echo "UpdateTime:".$updatetime."
";//到这里都正确!

$PointObj=$itemObj->getElementsByTagName('Point');//再去查找一下子节点
echo $PointObj->length;
}
}
?>

总报错:Fatal error: Call to undefined method DOMNodeList::getElementsByTagName() in C:\wamp\www\admin\interface\wallpaper_update.php on line 36

帮我看看这是为什么那!请师哥指正。



------解决方案--------------------

PHP code
$XMLStr=' <wallpaperlist>     <wallpaper id="69" updatetime="2008-12-10 12:00:00">         <point id="1">             <agent id="123456" updatetime="2008-12-10 12:00:00"></agent>             <agent id="123457" updatetime="2008-12-10 12:00:00"></agent>         </point>         <point id="2">             <agent id="123456" updatetime="2008-12-10 12:00:00"></agent>             <agent id="123457" updatetime="2008-12-10 12:00:00"></agent>         </point>     </wallpaper> </wallpaperlist>'; if($XMLStr!="") {     $XMLStr=stripcslashes($XMLStr);     $xml = new DOMDocument(); //建立一个DOMDocument     $xml->loadXML($XMLStr); //Php指定需要读取xml文件的位置     $itemObj = $xml->getElementsByTagName('WallPaper');//按照名称取得节点,返回所有节点的集合,不过这里这样读LevelOne是没有意义的....     for($i=0;$i length;$i++)     {             $id= $itemObj->item($i)->getAttribute("ID");         $updatetime= $itemObj->item($i)->getAttribute("UpdateTime");         echo "ID:".$id." <br>";         echo "UpdateTime:".$updatetime." <br>";//到这里都正确!                 $PointObj=$itemObj->item($i)->getElementsByTagName('Point');//再去查找一下子节点         echo $PointObj->length;     } }<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn