当前位置:网站首页>php内的addChild()、addAttribute()函数
php内的addChild()、addAttribute()函数
2022-07-02 05:47:00 【杰儿__er】
> addChild
<?php
/*SimpleXMLElement::addChild()函数接受表示XML元素的键和值的字符串值
并将其作为子元素添加到XML节点*/
$str = "<?xml version='1.0' encoding='UTF-8'?><Tutorial><Name>aa</Name></Tutorial>";
$xml = new SimpleXMLElement($str);
$tut = $xml->addChild('Tu');
$tut->addChild('Price', '60');
$simpleXml = $xml->asXML();
print_r($simpleXml);
/*
<?xml version="1.0" encoding="UTF-8"?>
<Tutorial>
<Name>aa</Name>
<Tu>
<Price>60</Price>
</Tu>
</Tutorial>
*/
?>
> addAttribute
<?php
$str = "<?xml version='1.0' encoding='UTF-8'?><Tutorial><Name>aa</Name></Tutorial>";
$xml = new SimpleXMLElement($str);
$xml->addAttribute("type", "private");
$xml->Name->addAttribute("date", "2022");
echo $xml->asXML();
/**语法addAttribute(name, value, ns)
* name 必需。 规定要添加的属性的名称
* value 可选。规定属性的值
* ns 可选。 规定属性的命名空间
*/
/*
<?xml version="1.0" encoding="UTF-8"?>
<Tutorial type="private"><Name date="2022">aa</Name></Tutorial>
*/
?>
边栏推荐
- Grbl software: basic knowledge of simple explanation
- idea開發工具常用的插件合集匯總
- [Chongqing Guangdong education] selected reading reference materials of British and American literature of Nanyang Normal University
- VSCode paste image插件保存图片路径设置
- Zzuli:1069 learn from classmate Z
- Zzuli:1067 faulty odometer
- Fabric. JS upload local image to canvas background
- Zzuli:1068 binary number
- Here comes a new chapter in the series of data conversion when exporting with easyexcel!
- Pytorch Basics
猜你喜欢
Practice C language advanced address book design
all3dp.com网站中全部Arduino项目(2022.7.1)
How matlab marks' a 'in the figure and how matlab marks points and solid points in the figure
centos8安装mysql8.0.22教程
Opencv LBP features
5g market trend in 2020
Cube magique infini "simple"
Balsamiq wireframes free installation
2022-2-14 learning xiangniuke project - section 23, section 5, development login and exit functions
Storage of data
随机推荐
线程池概述
Thread pool overview
"Simple" infinite magic cube
Principle and implementation of parallax effect
来啦~ 使用 EasyExcel 导出时进行数据转换系列新篇章!
7. Eleven state sets of TCP
文件包含漏洞(二)
【论文翻译】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
软件测试基础篇
kmp思想及模板代码
Yyds dry inventory what is test driven development
记录sentry的踩坑之路
《CGNF: CONDITIONAL GRAPH NEURAL FIELDS》阅读笔记
1036 Boys vs Girls
Ubuntu 20.04 installing mysql8
Fabric. JS activation input box
6. Network - Foundation
I want to understand the swift code before I learn it. I understand it
Generate QR code
centos8安裝mysql8.0.22教程