PHP对XML增删改查功能实现

这是网站主页,简单优化了一下,不过还是巨丑务必,见谅见谅,用到了PHP的simple_php插件,很简单,但是功能也有限,但是对于我们使用来说已经足够了。

<!DOCTYPE html>
<html>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0-rc1.js"></script>
	<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
	<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body>
<div text-align="center"><h3 >xml实验课作业:增删改查</h3></div>
<br>
<form role="form" action="change.php" method="post">
<div class="form-group">
	<div class="form-inline"><label for="name">标签:</label><input class="form-control" placeholder="请输入" type="text" name="id"></div>
	<div class="form-inline"><label for="name">属性:</label><input class="form-control" placeholder="请输入" type="text" name="value"></div>
	<button  class="btn btn-success" type="submit" >提交</button>
	</div>
</form>
<form action="delete.php" method="post">
	<div class="form-inline"><label for="name">删除标签:</label><input  placeholder="请输入" class="form-control"  type="text" name="id"></div>
	<button type="submit" class="btn btn-success">提交</button>
</form>
<br>
<div>所有信息:</div>
<?php
$xml=simplexml_load_file("note.xml");
echo $xml->getName() . "<br>";
foreach($xml->children() as $child)
{
    if($child!=''){
		echo "  ".$child->getName() . ": " . $child . "<br>";
	}
}
?>
</body>
</html>

下面代码是change.php,主要是将提交的增加或者修改命令进行执行

<!DOCTYPE html>
<html>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0-rc1.js"></script>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
	<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body>

<?php
$xml=simplexml_load_file("note.xml");
$id=$_POST["id"];
$value=$_POST["value"];
	//$xml->from=$from;直接修改方式
if($id!=''){
	$xml->$id=$value;
}
$xml->asXML('note.xml'); 
echo "修改完毕,请返回";
?>
<br>
<a href="http://123.206.58.204"> 返回</a>
<br>
<?php
$xml=simplexml_load_file("note.xml");
foreach($xml->children() as $child)
{
  if($child!=''){
		echo $child->getName() . ": " . $child . "<br>";
	}
}
?>
<br>
</html>
这个是delete.php,对标签进行删除

<!DOCTYPE html>
<html>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0-rc1.js"></script>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">  
	<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
	<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body>
<?php
$xml=simplexml_load_file("note.xml");
$id=$_POST["id"];
	//$xml->from=$from;直接修改方式
	$xml->$id=$value;
$xml->asXML('note.xml'); 
echo "修改完毕,请返回";
?>
<br>
<a href="http://123.206.58.204">返回</a>
<br>
<?php
$xml=simplexml_load_file("note.xml");
echo $xml->getName() . "<br>";
foreach($xml->children() as $child)
{
    if($child!=''){
		echo $child->getName() . ": " . $child . "<br>";
	}
}
?>
</body>
</html>

主要页面




  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值