Xiaomei encountered the problem of retrieving XML subnodes. Please help me to see 1. I have obtained the node of the level-1 directory, but I cannot find the node of the level-1 Directory. I don't know why I ask the teachers to correct it. & Lt ;? Php $ XMLStr = '& lt; WallPaperList & gt; & nbsp; & lt; WallPaperID = & quot; 69 & quot; Upd has encountered the problem of retrieving XML subnodes. Please help me to see 1
I have obtained the node of the level-1 directory, but I cannot obtain the node of the level-1 Directory.
I don't know why I ask the instructors to correct me.
$ XMLStr ='
';
If ($ XMLStr! = "")
{
$ XMLStr = stripcslashes ($ XMLStr );
$ Xml = new DOMDocument (); // Create a DOMDocument
$ Xml-> loadXML ($ XMLStr); // Php specifies the location where the xml file needs to be read
$ ItemObj = $ xml-> getElementsByTagName ('wallpaper'); // Get the node by name and return the set of all nodes. However, reading LevelOne is meaningless here ....
For ($ I = 0; $ I <$ itemObj-> length; $ I ++)
{
$ Id = $ itemObj-> item ($ I)-> getAttribute ("ID ");
$ Updatetime = $ itemObj-> item ($ I)-> getAttribute ("UpdateTime ");
Echo "ID:". $ id ."
";
Echo "UpdateTime:". $ updatetime ."
"; // All are correct here!
$ PointObj = $ itemObj-> getElementsByTagName ('point'); // you can find all nodes at once.
Echo $ PointObj-> length;
}
}
?>
Total error: Fatal error: Call to undefined method DOMNodeList: getElementsByTagName () in C: \ wamp \ www \ admin \ interface \ wallpaper_update.php on line 36
Let me see why! Please correct me.
------ Solution --------------------
PHP code
$ XMLStr ='
'; If ($ XMLStr! = "") {$ XMLStr = stripcslashes ($ XMLStr); $ xml = new DOMDocument (); // Create a DOMDocument $ xml-> loadXML ($ XMLStr ); // Php specifies the location of the xml file to be read $ itemObj = $ xml-> getElementsByTagName ('wallpaper '); // Obtain the node by name and return the set of all nodes, however, reading LevelOne is meaningless here .... for ($ I = 0; $ I <$ itemObj-> length; $ I ++) {$ id = $ itemObj-> item ($ I) -> getAttribute ("ID"); $ updatetime = $ itemObj-> item ($ I)-> getAttribute ("UpdateTime"); echo "ID :". $ id."
"; Echo" UpdateTime: ". $ updatetime ."
"; // All are correct here! $ PointObj = $ itemObj-> item ($ I)-> getElementsByTagName ('point'); // search for the instant node echo $ PointObj-> length ;}}