This article mainly introduces how to modify the content of xml documents through php, involving the assignment and saving operations of php for XML nodes. For more information, see
This article mainly introduces how to modify the content of xml documents through php, involving the assignment and saving operations of php for XML nodes. For more information, see
The example in this article describes how to modify the content of the xml document through php and share it with you for your reference. The specific implementation method is as follows:
The Code is as follows:
<? Php
// 1. Create a DOMDocument object. This object indicates an xml file.
$ Xmldoc = new DOMDocument ();
// 2. Load the xml file (specify the xml file to be parsed, And the dom tree node will be loaded to the memory)
$ Xmldoc-> load ("class. xml ");
// 3. Update the student information record and her age
// (1) Find the student
$ Student = $ xmldoc-> getElementsByTagName ("student ");
$ Stu1 = $ student-> item (0); // the first student
$ Stusponage = $ stu1-> getElementsByTagName ("age")-> item (0); // check her age
$ Stutesage-> nodeValue = 30;
// 4. Update the xml document
$ Xmldoc-> save ("class. xml ");
Echo "Update successful ";
?>
I hope this article will help you with the XML programming for php operations.
,