我试图让我的php代码以 XML 格式输出代码,但是我不确定如何让它正常工作。到目前为止,它以 php/html 格式输出代码。
这是我的 XML:
<bookcollection>
<items>
<item id="483">
<title>Database systems management and design/</title>
<isbn>0877091153</isbn>
<url>http://library.hud.ac.uk/catlink/bib/483</url>
<borrowedcount>28</borrowedcount>
<courses>
<course>CC140</course>
</courses>
</item>
</items>
</bookcollection>
和 PHP:
<?php
$xmlassignDoc = new DOMDocument();
$xmlassignDoc->load("books.xml");
$books = $xmlassignDoc->getElementsByTagName("item");
foreach($books as $list)
{
$bookID = $list->getAttribute("id");
//HERE is where the GET function will be
if ($bookID == '483')
{
$id = $list->getAttribute("id");
echo "<b>Book ID: </b> $id <br>";
$title = $list->getElementsByTagName("title");
$title = $title->item(0)->nodeValue;
echo "<b>Title: </b> $title <br>";
$isbn = $list->getElementsByTagName("isbn");
$isbn = $isbn->item(0)->nodeValue;
echo "<b>ISBN: </b> $isbn <br>";
$borrowed = $list->getElementsByTagName("borrowedcount");
$borrowed = $borrowed->item(0)->nodeValue;
echo "<b>Borrowed Count: </b> $borrowed <br>";
echo "<br>";
}
}
?>
任何想法都会对我有很大帮助。