Php cannot read data in xml through simplexml... I learned from Cainiao, but I didn't know how to beat me .. A product. xml document with the following content: (there are multiple similar item entries) & lt ;? Xmlversion & quot; 1.0 & quot; encoding & quot; UTF-8 & quot ;? & Gt; & lt; product & gt; & lt; item & gt; & lt; name & gt; p php cannot read data in xml through simplexml... I learned from Cainiao, but I didn't know how to beat me ..
A product. xml document with the following content: (there are multiple similar item entries)
Product1
Images/product.jpg
Discription...
The PHP document for calling data is
Untitled Document
$ Xml = simplexml_load_file ("products. xml ");
$ Part = $ xml-> product-> item;
$ K = 0;
While ($ k <12 ){
Echo"
-
". $ Part [$ k]-> name ."
-
Link. "'target = '_ blank'> picurl." 'alt = '". $ part [$ k]-> name."'/>
-
". $ Part [$ k]-> discription ."
";
$ K ++;
}
?>
The HTML statements output in the call results are correct. But there is no data in the xml document label.
Please kindly advise !!!!! Thank you ~~~~~ PS: I am a pure Cainiao, and my table is so contemptible...
------ Solution --------------------
$ Part = $ xml-> product-> item;
Should be
$ Part = $ xml-> item;
That is, the root node is not in the access column.
You can observe this through print_r ($ xml ).