通过php修改xml文档内容的方法
作者:shichen2014 时间:2024-06-07 15:45:30
本文实例讲述了通过php修改xml文档内容的方法,分享给大家供大家参考。具体实现方法如下:
<?php
//1、创建一个DOMDocument对象。该对象就表示 xml文件
$xmldoc = new DOMDocument();
//2、加载xml文件(指定要解析哪个xml文件,此时dom树节点就会加载到内存中)
$xmldoc->load("class.xml");
//3、更新一条学生student信息记录,更新她的年龄
//(1)找到该学生
$student = $xmldoc->getElementsByTagName("student");
$stu1 = $student->item(0);//第一个学生
$stu1_age = $stu1->getElementsByTagName("age")->item(0);//查到她的年龄
$stu1_age->nodeValue = 30;
//4、更新 xml 文档
$xmldoc->save("class.xml");
echo "更新成功";
?>
希望本文所述对大家的php操作XML程序设计有所帮助。
标签:php,修改,xml
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python占位符输入方式实例
2022-10-26 11:46:16
多种方式实现js图片预览
2024-04-23 09:24:44
Python的Bottle框架中返回静态文件和JSON对象的方法
2023-11-07 20:14:41
![](https://img.aspxhome.com/file/2023/4/66374_0s.png)
Python logging自定义字段输出及打印颜色
2023-09-03 17:04:25
vue+canvas实现拼图小游戏
2024-05-09 15:09:34
![](https://img.aspxhome.com/file/2023/3/126613_0s.jpg)
仿vue-cli搭建属于自己的脚手架的方法步骤
2024-05-21 10:18:09
Python实现的维尼吉亚密码算法示例
2023-08-25 10:19:25
![](https://img.aspxhome.com/file/2023/7/90807_0s.png)
使用Title提升可访问性
2009-04-04 17:06:00
![](https://img.aspxhome.com/file/UploadPic/20094/4/title_blueidea-67s.png)
Django配置跨域并开发测试接口
2022-03-20 21:29:08
![](https://img.aspxhome.com/file/2023/2/121162_0s.png)
Laravel中使用阿里云OSS Composer包分享
2023-11-04 23:31:23
python3使用QQ邮箱发送邮件
2023-09-05 05:16:15
![](https://img.aspxhome.com/file/2023/3/130943_0s.jpg)
深入理解Python中变量赋值的问题
2023-03-20 00:28:07
新手入门:防范SQL注入攻击的新办法
2009-03-11 15:14:00
Sql server中时间查询的一个比较快的语句
2008-12-29 14:16:00
PHPExcel笔记, mpdf导出
2024-06-05 09:44:57
浅析Go语言中闭包的使用
2024-02-16 12:35:18
![](https://img.aspxhome.com/file/2023/3/113103_0s.png)
Django后端接收嵌套Json数据及解析详解
2021-04-24 20:11:38
![](https://img.aspxhome.com/file/2023/1/105711_0s.png)
python批量从es取数据的方法(文档数超过10000)
2022-03-23 01:21:48
asp下用fso和ado.stream写xml文件的方法
2011-04-07 10:55:00
用JavaScript实现UrlEncode和UrlDecode功能
2008-01-27 11:30:00