我正在尝试使用dom编写xml
但使用dom制作xml的php代码会产生错误。
prototype.js:1739 GET http://localhost/booksearch/books.php?category=children 500(内部服务器错误)
在PHP代码创建xml关于书籍更改为dom样式之前,没有错误
造成这个错误的原因是什么?
$xmldom = new DOMDocument();
$books_tag = $xmldoc->createElement("books");
$xmldom->appendChild($books_tag);
$lines = file($BOOKS_FILE);
for ($i = 0; $i < count($lines); $i++) {
list($title, $author, $book_category, $year, $price) = explode("|", trim($lines[$i]));
if ($book_category == $category) {
$book_tag = $xmldom->createElement("book");
$category_tag = $xmldom->crateElement("category");
$category_tag->appendChild($xmldom->createTextNode($category));
$book_tag->appendChild($category_tag);
$title_tag = $xmldom->createElement("title");
$title_tag->appendChild($xmldom->createTextNode($title));
$book_tag->appendChild($title_tag);
$author_tag = $xmldom->createElement("author");
$author_tag->appendChild($xmldom->createTextNode($author));
$book_tag->appendChild($author_tag);
$year_tag = $xmldom->createElement("year");
$year_tag->appendChild($xmldom->creatTextNode($year));
$book_tag->appendChild($year_tag);
$price_tag = $xmldom->createElement("price");
$price_tag->appendChild($xmldom->creatTextNode($price));
$book_tag->appendChild($price_tag);
$books_tag->appendChild($book_tag);
}
}
header("Content-type: text/txt");
echo $xmldoc->saveXML();