bookss文档内容如下:
<?xml version="1.0" ?>
<books>
<book>
<author>Jane Doe</author>
<Title>A very good book</Title>
<publisher>hdhdh</publisher>
</book>
<book>
<author>Jane Doe</author>
<Title>A very good book</Title>
<publisher>hdhdh</publisher>
</book>
</books>
php代码如下:
<?php
$doc= new DOMDocument();
$doc->load('bookss.xml');
$books=$doc->getElementsByTagName("book");
foreach($books as $book)
{
$authors=$book->getElementByTagName("author");
$author=$authors->item(0)->nodeValue;
$publishers=$book->getElementByTagName("publisher");
$publisher=$publishers->item(0)->nodeValue;
$Titles=$book->getElementByTagName("Title");
$Title=$Titles->item(0)->nodeValue;
echo"$Title-$author-$publisher\n";
}
?>为什么输不出结果呢??请大家指点哈。谢谢了