Home > Backend Development > PHP Tutorial > How to modify the content of xml document through php, modify xml document with php_PHP tutorial

How to modify the content of xml document through php, modify xml document with php_PHP tutorial

WBOY
Release: 2016-07-13 10:09:20
Original
919 people have browsed it

How to modify the content of xml document through php, modify xml document with php

The example in this article describes the method of modifying the content of xml document through php, and shares it with everyone for your reference. The specific implementation method is as follows:

Copy code The code is as follows:
//1. Create a DOMDocument object. This object represents the xml file
$xmldoc = new DOMDocument();
//2. Load the xml file (specify which xml file to parse, then the dom tree node will be loaded into the memory)
$xmldoc->load("class.xml");
//3. Update a student information record and update her age
//(1)Find the student
$student = $xmldoc->getElementsByTagName("student");
$stu1 = $student->item(0);//The first student
$stu1_age = $stu1->getElementsByTagName("age")->item(0);//Find her age
$stu1_age->nodeValue = 30;
//4. Update xml document
$xmldoc->save("class.xml");
echo "Update successful";
?>

I hope this article will be helpful to everyone’s PHP XML programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/946734.htmlTechArticleHow to modify the content of xml document through php, modify the xml document through php. This article describes how to modify the content of xml document through php. The method is shared with everyone for your reference. The specific implementation method is as follows:...
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