当前位置:网站首页>Addchild() and addattribute() functions in PHP
Addchild() and addattribute() functions in PHP
2022-07-02 05:49:00 【Jill__ er】
> addChild
<?php
/*SimpleXMLElement::addChild() Function acceptance representation XML The string value of the key and value of the element
And add it as a child element to XML node */
$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();
/** grammar addAttribute(name, value, ns)
* name It's necessary . Specify the name of the attribute to be added
* value Optional . Specify the value of the property
* ns Optional . Specify the namespace of the attribute
*/
/*
<?xml version="1.0" encoding="UTF-8"?>
<Tutorial type="private"><Name date="2022">aa</Name></Tutorial>
*/
?>
边栏推荐
- Fabric. JS gradient
- Simply encapsulate JS and apply it
- Fabric. JS round brush
- php数组转化为xml
- Balsamiq wireframes free installation
- Zzuli:1060 numbers in reverse order
- Centos8 installation mysql8.0.22 tutorial
- 15 C language advanced dynamic memory management
- Matplotlib double Y axis + adjust legend position
- 记录sentry的踩坑之路
猜你喜欢

mysql的约束总结

idea开发工具常用的插件合集汇总

The Hong Kong Stock Exchange learned from US stocks and pushed spac: the follow-up of many PE companies could not hide the embarrassment of the world's worst stock market

Conglin environmental protection rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, with an annual profit of more than 200million yuan

centos8安裝mysql8.0.22教程

Importation de studio visuel

“简单”的无限魔方

Software testing learning - day 4

Youth training camp -- database operation project

Grbl software: basic knowledge of simple explanation
随机推荐
brew install * 失败,解决方法
h5跳小程序
1037 Magic Coupon
KMP idea and template code
kmp思想及模板代码
LCD之MIPI协议的一些说明
RNN recurrent neural network
Usage record of vector
Zzuli:1067 faulty odometer
生成二维码
RGB 无限立方体(高级版)
Opencv LBP features
A collection of commonly used plug-ins for idea development tools
460. LFU 缓存 双向链表
Zzuli: maximum Convention and minimum common multiple
Uva548 tree
php读文件(读取json文件,转换为数组)
460. LFU cache bidirectional linked list
Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?
Zzuli:1061 sequential output of digits