分别是创建、增加、删除、修改四个功能,变量都是写死的,改一改用$_post方式接收就可以用了
//index.php教程 创建功能
复制代码 代码如下:
$xmlpatch = 'index.xml';
$_id = '1';
$_title = 'title1';
$_content = 'content1';
$_author = 'author1';
$_sendtime = 'time1';
$_htmlpatch = '1.html';
111com.net$doc = new domdocument('1.0', 'utf-8');
$doc -> formatoutput = true;
111com.net$root = $doc -> createelement('root');//新建节点
111com.net$index = $doc -> createelement('index');//新建节点
111com.net$url = $doc -> createattribute('url');//新建属性
$patch = $doc -> createtextnode($_htmlpatch);//新建text值
$url -> appendchild($patch);//将$patch文本设为$url属性的值
111com.net$id = $doc -> createattribute('id');
$newsid = $doc -> createtextnode($_id);
$id -> appendchild($newsid);
111com.net$title = $doc -> createattribute('title');
$newstitle = $doc -> createtextnode($_title);
$title -> appendchild($newstitle);
111com.net$content = $doc -> createtextnode($_content);//节点值
111com.net$author = $doc -> createattribute('author');
$newsauthor = $doc -> createtextnode($_author);
$author -> appendchild($newsauthor);
111com.net$sendtime = $doc -> createattribute('time');
$newssendtime = $doc -> createtextnode($_sendtime);
$sendtime -> appendchild($newssendtime);
111com.net$index -> appendchild($id);//将$id设为index节点的属性,以下类同
$index -> appendchild($title);
$index -> appendchild($content);
$index -> appendchild($url);
$index -> appendchild($author);
$index -> appendchild($sendtime);
111com.net$root -> appendchild($index);//设置index为root字节点
111com.net$doc -> appendchild($root);//设置root为跟节点
111com.net$doc -> save($xmlpatch);//保存文件
111com.netecho $xmlpatch . ' has create success';
111com.net?>
111com.net
//add.php 增加功能(跟index.php文件差不多,主要就是加个load载入跟 $root = $doc -> documentelement获得跟节点
复制代码 代码如下:
$xmlpatch = 'index.xml';
$_id = '2';
$_title = 'title2';
$_content = 'content2';
$_author = 'author2';
$_sendtime = 'time2';
$_htmlpatch = '2.html';
111com.net$doc = new domdocument();
$doc -> formatoutput = true;
if($doc -> load($xmlpatch)) {
$root = $doc -> documentelement;//获得根节点(root)
$index = $doc -> createelement('index');
111com.net$url = $doc -> createattribute('url');
$patch = $doc -> createtextnode($_htmlpatch);
$url -> appendchild($patch);
111com.net$id = $doc -> createattribute('id');
$newsid = $doc -> createtextnode($_id);
$id -> appendchild($newsid);
111com.net$title = $doc -> createattribute('title');
$newstitle = $doc -> createtextnode($_title);
$title -> appendchild($newstitle);
111com.net$content = $doc -> createtextnode($_content);
111com.net$author = $doc -> createattribute('author');
$newsauthor = $doc -> createtextnode($_author);
$author -> appendchild($newsauthor);
111com.net$sendtime = $doc -> createattribute('time');
$newssendtime = $doc -> createtextnode($_sendtime);
$sendtime -> appendchild($newssendtime);
111com.net$index -> appendchild($id);
$index -> appendchild($title);
$index -> appendchild($content);
$index -> appendchild($url);
$index -> appendchild($author);
$index -> appendchild($sendtime);
111com.net$root -> appendchild($index);
111com.net$doc -> save($xmlpatch);
111com.netecho $_id . ' has been added in ' . $xmlpatch;
111com.net} else {
echo 'xml file loaded error!';
}
?>
//edit.php 修改功能(这里只修改title属性值 跟节点值)
复制代码 代码如下:
$xmlpatch = 'index.xml';
$_id = '2';
$_title = 'has been changed';
$_content = 'has been changed';
111com.net$doc = new domdocument();
$doc -> formatoutput = true;
111com.netif($doc -> load($xmlpatch)) {
$root = $doc -> documentelement;
$elm = $root -> getelementsbytagname('index');
$checkexist = 0;
foreach ($elm as $new) {
if($new -> getattribute('id') == $_id) {
$new -> setattribute('title', $_title);
$new -> nodevalue = $_content;//修改节点值,真是太意外了,没想到跟js一样直接能赋值...
//$new -> removechild($new -> nodevalue);
$checkexist = 1;
}
}
if($checkexist == 0) {
echo $_id . ' is not found in ' . $xmlpatch;
} else {
$doc -> save($xmlpatch);
echo $_id . ' has been changed';
}
} else {
echo 'xml file loaded error!';
}
111com.net?>
//del.php 删除功能
复制代码 代码如下:
$xmlpatch = 'index.xml';
$_id = '2';
111com.net$doc = new domdocument();
$doc -> formatoutput = true;
if($doc -> load($xmlpatch)) {
$root = $doc -> documentelement;
$elm = $root -> getelementsbytagname('index');
foreach ($elm as $new) {
if($new -> getattribute('id') == $_id) {
if($root -> removechild($new)) {
echo $_id . ' has been deleted';
} else {
echo $_id . ' delete failed';
}
}
}
$doc -> save($xmlpatch);
} else {
echo 'xml file loaded error!';
}
111com.net?>
我的博物馆故事 官方安卓版v1.61.2
我的博物馆故事是一款以消除为主题的经营养成类手游,在这里玩家
专业模拟飞行10 手机版v12.2.4
专业模拟飞行10安卓版是一款飞行休闲手游,顶尖的物理飞行引擎
动物起义战斗模拟器二琳同款 最新版v4.1.1
动物起义战斗模拟器是一个非常有趣的模拟类游戏,玩家可以召唤各
迷你世界七周年 安卓手机版v1.43.0
迷你世界7周年是一款由《迷你世界》官方推出的庆祝特别版本,在
劫后公司无限资源版 v1.0.5.1
劫后公司内置菜单版是游戏的破解版本,在该版本中为玩家提供了内