? Phppublicfunctionparsexml ($ menus) {$ result...
Nodename! = '# Text') {// when retrieving child elements, skip the text node-handle empty text node mode B for ($ I = 1; $ I <$ menu-> childnodes-> length; $ I + = 2) {$ anode = $ menu-> childnodes-> item ($ I ); // traverse the child element $ anode-> childnodes-> length> 1? $ Tmparr [$ anode-> nodename] = $ this-> parsexml ($ anode-> childnodes): $ tmparr [$ anode-> nodename] = $ anode-> nodevalue ;} array_push ($ result, $ tmparr) ;}return $ result ;}$ doc = new domdocument (); $ doc-> load ('A. XML'); // first, empty text node $ menus = $ doc-> getelementsbytagname ('sitemap')-> item (0)-> childnodes; // second, the label is specified, and no empty text node is found in the sequence. However, the child element still has a blank node $ xpath = new domxpath ($ doc); $ query = "/sitemap/child: "; $ menus = $ xpath-> query ($ query );
Tutorial link:
Reprint at will ~ However, please keep the tutorial address★