Xiaomei encountered the problem of retrieving XML subnodes. Please help me to see 1

Source: Internet
Author: User
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 ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.