当前位置:网站首页>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>
*/
?>
边栏推荐
- Straighten elements (with transition animation)
- Zzuli: maximum Convention and minimum common multiple
- Gee series: Unit 4 data import and export in Google Earth engine
- 2022-2-15 learning xiangniuke project - Section 8 check login status
- How matlab marks' a 'in the figure and how matlab marks points and solid points in the figure
- mysql事务和隔离级别
- Basic use of form
- Determine whether there is an element in the string type
- 1037 Magic Coupon
- 来啦~ 使用 EasyExcel 导出时进行数据转换系列新篇章!
猜你喜欢

Minimum value ruler method for the length of continuous subsequences whose sum is not less than s

青训营--数据库实操项目

Gee series: Unit 1 Introduction to Google Earth engine

Practice C language advanced address book design

RGB infinite cube (advanced version)

"Original, excellent and vulgar" in operation and maintenance work

3D 打印机 G 代码命令:完整列表和教程

Cube magique infini "simple"

Vite打包后的dist不能直接在浏览器打开吗

Matplotlib double Y axis + adjust legend position
随机推荐
青训营--数据库实操项目
Gee series: unit 9 generate sampling data in GEE [random sampling]
js判断移动端还是pc端
小程序跳装到公众号
Sliding window on the learning road
Determine whether there is an element in the string type
"Original, excellent and vulgar" in operation and maintenance work
XSS basic content learning (continuous update)
Zzuli:1066 character classification statistics
centos8安裝mysql8.0.22教程
Zzuli:1067 faulty odometer
Installation du tutoriel MySQL 8.0.22 par centos8
OLED12864 液晶屏
mysql的约束总结
Fabric. JS centered element
【論文翻譯】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
KMP idea and template code
GRBL 软件:简单解释的基础知识
Uva548 tree
kmp思想及模板代码