PHPコードでXMLを解析していて、 "foreachで無効な引数が指定されました"という警告が表示されています。以下 はXMLです:foreachの引数が無効です
<?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>
と次のコードを使用して:
<?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 />";
}
}
?>
注:私は、私は必要な出力が得られますが、警告で。配列が空でないことを示します。 はまた、出力を参照してください。
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
タグ間の空白がtextnodeを生成します。 – mario