foreach için verilen geçersiz argüman

0 Cevap php

I am parsing XML in PHP code and getting a warning "invalid argument supplied for foreach". Below is the XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<BookStore>
    <book>
        <title>Computer Concepts</title>
        <auther>Goerge Arthar</auther>
        <category>Computer Science</category>
        <price>24.00</price>
    </book>
    <book>
        <title>Algebra</title>
        <auther>Mike</auther>
        <category>Mathematics</category>
        <price>34.00</price>
    </book>
</BookStore>

ve aşağıdaki kodu kullanarak:

<?php
$xmlDOM = new DOMDocument();
$xmlDOM->load("Books.xml");
$document = $xmlDOM->documentElement;
foreach ($document->childNodes as $node) {   
    foreach($node->childNodes as $temp) {
        echo $temp->nodeName."=".$temp->nodeValue."<br />";
    }
}
?>

NOTE: I get the output that I require but with a warning. It shows that array is not empty. Please see output also:

Warning: Invalid argument supplied for foreach() in D:\program Files\wamp\www\Test web\Day2\xmlparsing.php on line 8
#text=
title=Computer Concepts
#text=
auther=Goerge Arthar
#text=
category=Computer Science
#text=
price=24.00
#text=

Warning: Invalid argument supplied for foreach() in D:\program Files\wamp\www\Test web\Day2\xmlparsing.php on line 8
#text=
title=Algebra
#text=
auther=Mike
#text=
category=Mathematics
#text=
price=34.00
#text=

Warning: Invalid argument supplied for foreach() in D:\program Files\wamp\www\Test web\Day2\xmlparsing.php on line 8

0 Cevap