PHP实现对xml的增删改查操作案例分析
php  /  管理员 发布于 7年前   179
本文实例讲述了PHP实现对xml的增删改查操作。分享给大家供大家参考,具体如下: 案例: index.php demo2.xml PS:这里再为大家提供几款关于xml操作的在线工具供大家参考使用: 在线XML/JSON互相转换工具: 在线格式化XML/在线压缩XML: XML在线压缩/格式化工具: XML代码在线格式化美化工具: 更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP针对XML文件操作技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP错误与异常处理方法总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》 希望本文所述对大家PHP程序设计有所帮助。load("demo2.xml");//查询学生信息$stus = $xmldom->getElementsByTagName("学生");for ($i=0;$i<$stus->length;$i++){ $stu = $stus->item($i); getxmlnode($stu, "姓名"); getxmlnode($stu, "年龄"); getxmlnode($stu, "性别"); getxmlnode($stu, "介绍");}function getxmlnode(&$stu,$tagname){ echo $stuname = $stu->getElementsByTagName($tagname)->item(0)->nodeValue."
";}//添加一个学生信息//addxml($xmldom);function addxml($xmldom){ $root = $xmldom->getElementsByTagName("班级")->item(0); $ostus = $xmldom->createElement_x_x("学生"); //添加属性 $ostus->setAttribute("恋爱状况","热恋中"); //$ostus->nodeValue="\r\n"; $root->a($ostus); $ostu_name = $xmldom->createElement_x_x("姓名"); $ostus->a($ostu_name); $ostu_name->nodeValue="小娜"; $ostu_sex = $xmldom->createElement_x_x("性别"); $ostus->a($ostu_sex); $ostu_sex->nodeValue="女"; $ostu_age = $xmldom->createElement_x_x("年龄"); $ostus->a($ostu_age); $ostu_age->nodeValue="23"; $ostu_intro = $xmldom->createElement_x_x("介绍"); $ostus->a($ostu_intro); $ostu_intro->nodeValue="高一美女"; $xmldom->save("demo2.xml");}//删除一个学生信息//del_element($xmldom);function del_element($xmldom){ $dstus = $xmldom->getElementsByTagName("学生"); $laststu = $dstus->item($dstus->length-1); $laststu->parentNode->removeChild($laststu);}//修改一个学生信息//update_element($xmldom);function update_element($xmldom){ $ustus = $xmldom->getElementsByTagName("学生"); $ustu = $ustus->item(0); $ustu_age = $ustu->getElementsByTagName("年龄")->item(0); $ustu_age->nodeValue+=10;}//写会到文件中$xmldom->save("demo2.xml");?><班级>班级>
http://tools..net.cn/code/xmljson
http://tools..net.cn/code/xmlformat
http://tools..net.cn/code/xml_format_compress
http://tools..net.cn/code/xmlcodeformat您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号