How to use simplexml to get the node name in php I tried to use phpsimplexml's getName () to get the node name, but it is not easy to know why please take a look at the content of the xml file as follows: & lt; root & gt; & nbsp; & lt; collectionid & quot; new1 & quot; & gt; & nbsp; & lt; category & g PHP how to get the node name using simple xml
I tried to use the getName () of php simple xml to get the node name, but I am not sure why can't I help you?
The content of the xml file is roughly as follows:
Aaa
Php code:
$ Xmldoc = simplexml_load_file ("test. xml ");
Foreach ($ xmldoc-> children () as $ child ){
Foreach ($ child-> attributes () as $ a => $ B ){
Echo $ B; // Print the property value of the collection here. it works normally.
}
Echo $ child-> getName (); // an error occurs when you try to name the node.
}
The normal result is new1 collection, but if new1 is available, the collection cannot be created. it seems that the page still has an error and I cannot find the cause. Is getName () incorrect?
------ Solution --------------------
No problem
It may be related to your php version.
------ Solution --------------------
Conversion between XML and PHP encapsulation function: xmlparse. php
PHP code
Aaa
XML; require (dirname (_ FILE __). "/xmlparse. php "); $ cont = parse_xml_config ($ contxml," root "); $ keys = array_keys ($ cont); $ key1 = array_keys ($ cont ['collect']); print_r ($ cont); # Array ([collection] => Array ([category] => aaa) [encoding] => UTF-8) print_r ($ keys ); # Array ([0] => collection [1] => encoding) print_r ($ key1); # Array ([0] => category)?>
------ Solution --------------------
Php5.3 Wood problems