This article illustrates the way to modify the content of XML documents through PHP, and share them for everyone's reference. The implementation methods are as follows:
Copy Code code as follows:
<?php
1, create a DOMDocument object. The object represents an XML file
$xmldoc = new DOMDocument ();
2. Load XML file (specify which XML file to parse, at which point the DOM tree node will be loaded into memory)
$xmldoc->load ("Class.xml");
3, update a student student information record, update her age
(1) Find the student
$student = $xmldoc->getelementsbytagname ("student");
$stu 1 = $student->item (0);//The First Student
$stu 1_age = $stu 1->getelementsbytagname ("Age")->item (0); Find out how old she is.
$stu 1_age->nodevalue = 30;
4. Update XML document
$xmldoc->save ("Class.xml");
echo "Update succeeded";
?>
I hope this article will help you with your PHP operating XML program.