PHP cannot read data in XML through SimpleXML. Pure beginner learning, less pat I ha.

Source: Internet
Author: User
PHP cannot read data in XML via SimpleXML ... Pure rookie study, less pat me ha.
A product.xml document with the following content: (Similar item entry has multiple)




Product1
Images/product.jpg
Discription...discription ...



The content of the PHP document that invokes the data is




<title>Untitled Document</title>



$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 result is called, and the output HTML statements are all right. But there is no data in the XML document tag.
Request for ENLIGHTEN!!!!! Appreciate ~~~~~ps: I am a pure rookie, the table excessively despise me ...

------Solution--------------------
$part = $xml->product->item;
should be for
$part = $xml->item;

That is, the root node is not in the Access column
This you can observe by 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.