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.
http://www.bkjia.com/PHPjc/946734.htmlwww.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:...