1 public function parseXML ($ menus ){
2 $ result = array ();
3 foreach ($ menus as $ menu ){
4 $ tmparr = array ();
5
6 // process empty text Node Method
7 if ($ menu-> nodeName! = '# Text '){
8
9 // skip the text node When retrieving child elements-Method B for processing empty text nodes
10 for ($ I = 1; $ I <$ menu-> childNodes-> length; $ I + = 2 ){
11 $ aNode = $ menu-> childNodes-> item ($ I );
12
13 // subelement Traversal
14 $ aNode-> childNodes-> length> 1? $ Tmparr [$ aNode-> nodeName] = $ this-> parseXML ($ aNode-> childNodes)
15: $ tmparr [$ aNode-> nodeName] = $ aNode-> nodeValue;
16}
17 array_push ($ result, $ tmparr );
18}
19}
20 return $ result;
21}
22
23
24
25 $ doc = new DOMDocument ();
26 $ doc-> load ('A. xml ');
27
28 // first, empty text node
29 $ menus = $ doc-> getElementsByTagName ('sitemap')-> item (0)-> childNodes;
30
31 // type 2: Specify the tag, and the sequence does not contain empty text nodes. But the child element is still empty.
32
33 $ xpath = new DOMXPath ($ doc );
34 $ query = "/siteMap/child: ";
35
36 $ menus = $ xpath-> query ($ query );