求助,关于XML方面的
我在本地建了三个文件,一个静态表单文件,还有一个php脚本文件,另外还有一个xml文件,三个文件的具体代码如下:
post.php
<?php
$guestbook=new DomDocument();
//创建一个新的DOMain对象
$guestbook->load('db/gusetbook.xml');
//读取XML数据
$threads=$guestbook->documentElement;
//获得XML结构的根
//下面创建一个新thread节点
$thread=$gusetbook->createElement('thread');
$threads->appendChild($thread);
//在新的thread节点上创建title标签
$title=$guestbook->createElement('title');
$title->appendChild($gusetbook->createTextNode($_POST['title']));
$thread->appendChild($title);
//在新的thread节点上创建author标签
$author=$guestbook->createElement('author');
$author->appendChild($gusetbook->createTextNode($_POST['author']));
$thread->appendChild($author);
//在新的thread节点上创建content标签
$content=$guestbook->createElement('content');
$content->appendChild($gusetbook->createTextNode($_POST['content']));
$thread->appendChild($content);
//将XML数据写入文件
$fp=fopen("DB/guestbook.xml","w");
if(fwrite($fp,$guestbook->saveXML()))
echo "留言提交成功";
else
echo "留言提交失败";
fclose($fp);
?> ;
insert.html:
<html>
<head>
<title>发表新的留言</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h1><p align="center">发表新的留言</p></h1>
<form name="form1" method="post" action="post.php">
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>标题</td>
<td><input type="text" name="title" id="title" size="50"></td>
</tr>
<tr>
<td>作者</td>
<td><input type="text" name="author" id="author" size="20"></td>
</tr>
<tr>
<td>内容</td>
<td><textarea name="content" cols="50" rows="10" id="content"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="提交">
<input type="reset" name="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html> ;
db/guestbook.xml:
<?xml version="1.0"?>
<threads>
<thread>
<title>这里是留言的标题</title>
<author>这里是留言者</author>
<content>这里是留言内容</content>
</thread>
</threads> ;
结果屏幕显示如下,有哪位知道的告诉下,谢谢!
Warning: DOMDocument::load() [
domdocument.load]: I/O warning : failed to load external entity "file:///D:/Inetpub/wwwroot/exercises/XML/3/db/gusetbook.xml" in
D:\Inetpub\wwwroot\exercises\XML\3\post.php on line
4
Fatal error: Call to a member function createElement() on a non-object in
D:\Inetpub\wwwroot\exercises\XML\3\post.php on line
9