Home > php教程 > php手册 > body text

通过php修改xml文档内容的方法,php修改xml文档

WBOY
Release: 2016-06-13 09:16:49
Original
948 people have browsed it

通过php修改xml文档内容的方法,php修改xml文档

本文实例讲述了通过php修改xml文档内容的方法,分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:

//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程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!