PHP modifies XML document _php tutorial using PHP to modify the content of XML documents

Source: Internet
Author: User

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: ...

  • 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.