[PHP] Add, delete, modify and check xml study notes (1) Added

little bottle
Release: 2023-04-05 21:48:02
forward
2776 people have browsed it

This article mainly introduces the implementation method of PHP's deletion, modification and check operation of XML files. It analyzes the operation skills of PHP's addition of XML files in the form of specific examples. Friends in need can refer to it.

xml file

 <班级> <学生> <名字>大哈 <年龄>30 <介绍>学生刻苦  <学生> <名字>二哈 <年龄>35 <介绍>学生好  <学生 性别="男"> <名字>哈哈 <年龄>100 <介绍>这是小哈  
Copy after login

Related tutorials:xml video tutorial

Add

load("classes.xml"); //3.添加学生信息 //(1)取出根节点 $root=$xmldoc->getElementsByTagName("班级")->item(0); //(2)创建学生节点 $stu_node=$xmldoc->createElement("学生"); //添加属性节点 $stu_node->setAttribute("性别","男"); //(3)创建名字节点 $stu_node_name=$xmldoc->createElement("名字"); $stu_node_name->nodeValue="哈哈"; //把名字节点挂载到学生节点下 $stu_node->appendChild($stu_node_name); //创建年龄 $stu_node_age=$xmldoc->createElement("年龄"); $stu_node_age->nodeValue="100"; $stu_node->appendChild($stu_node_age); //创建介绍 $stu_node_intro=$xmldoc->createElement("介绍"); $stu_node_intro->nodeValue="这是小哈"; $stu_node->appendChild($stu_node_intro); //把学生节点挂载到根节点下 $root->appendChild($stu_node); //重新保存回xml //如果save到源文件,则相当于是对文件更新 //如果save是新的文件名,则连同原来文件的内容和新添加的内容都保存到新文件里 $xmldoc->save("classes.xml"); ?>
Copy after login

Related tutorials:PHP video tutorial

The above is the detailed content of [PHP] Add, delete, modify and check xml study notes (1) Added. For more information, please follow other related articles on the PHP Chinese website!

source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!