Php cannot read data in xml through simplexml. I am a beginner.

Source: Internet
Author: User
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 ).

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.