Ways to modify XML document content through PHP _php tips

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.