当前位置:网站首页>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>
*/
?>
边栏推荐
- 5g market trend in 2020
- Principle and implementation of parallax effect
- With an amount of $50billion, amd completed the acquisition of Xilinx
- Disable access to external entities in XML parsing
- Usage record of vector
- 《CGNF: CONDITIONAL GRAPH NEURAL FIELDS》阅读笔记
- Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea
- KMP idea and template code
- Zzuli: maximum Convention and minimum common multiple
- Fabric. JS basic brush
猜你喜欢
![Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]](/img/1e/cf0aa09c2fce2278386f12eae4a6cd.jpg)
Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]

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

Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?

“簡單”的無限魔方

RNN recurrent neural network

brew install * 失败,解决方法

Appnuim environment configuration and basic knowledge

测试 - 用例篇

Principle and implementation of parallax effect

RGB 无限立方体(高级版)
随机推荐
运动健身的一些心得经验
Importation de studio visuel
Zzuli:1064 encrypted characters
Gee series: Unit 1 Introduction to Google Earth engine
记录sentry的踩坑之路
Taskbar explicit / implicit toggle function
460. LFU cache bidirectional linked list
Fabric. JS right click menu
1036 Boys vs Girls
centos8安装mysql8.0.22教程
Record sentry's path of stepping on the pit
2022-2-14 learning xiangniuke project - section 23, section 5, development login and exit functions
Usage record of vector
Uva548 tree
Visual studio import
h5跳小程序
all3dp.com网站中全部Arduino项目(2022.7.1)
Principle and implementation of parallax effect
【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘
Fabric. JS centered element