PHP modifies XML document content by PHP
In this paper, we describe the method of modifying XML document content through PHP, and share it for your reference. The implementation method is as follows:
Copy the Code code as follows: <?php
1. Create a DOMDocument object. The object represents the XML file
$xmldoc = new DOMDocument ();
2. Load the XML file (specifies which XML file to parse, at which point the DOM tree node is 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);//First Student
$stu 1_age = $stu 1->getelementsbytagname ("Age")->item (0);//Find her old.
$stu 1_age->nodevalue = 30;
4. Update the XML document
$xmldoc->save ("Class.xml");
echo "Update succeeded";
?>
I hope this article is helpful to everyone's PHP operation XML programming.
http://www.bkjia.com/PHPjc/946734.html www.bkjia.com true http://www.bkjia.com/PHPjc/946734.html techarticle using PHP to modify the contents of the XML document method, PHP modified XML documents in this article is about the way to modify the content of XML documents through PHP, share to everyone for your reference. The concrete implementation method is as follows: ...