当前位置:网站首页>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>
*/
?>
边栏推荐
- VSCode paste image插件保存图片路径设置
- Appnuim environment configuration and basic knowledge
- Vscode paste image plugin saves image path settings
- Record sentry's path of stepping on the pit
- Uva548 tree
- Practice C language advanced address book design
- Here comes a new chapter in the series of data conversion when exporting with easyexcel!
- "Original, excellent and vulgar" in operation and maintenance work
- Fabric. JS round brush
- Financial portal related information
猜你喜欢
文件包含漏洞(一)
Pytorch Basics
3D 打印机 G 代码命令:完整列表和教程
正则表达式总结
PHP 开发与测试 Webservice(SOAP)-Win
Visual Studio导入
2022-2-15 learning xiangniuke project - Section 8 check login status
Grbl software: basic knowledge of simple explanation
【論文翻譯】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
Youth training camp -- database operation project
随机推荐
Zzuli:1067 faulty odometer
死磕大屏UI,FineReport开发日记
Visual studio import
生成二维码
1037 Magic Coupon
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
2022-2-14 learning xiangniuke project - Section 7 account setting
Fabric. JS free draw rectangle
来啦~ 使用 EasyExcel 导出时进行数据转换系列新篇章!
软件测试 - 概念篇
2022-2-14 learning xiangniuke project - Section 6 displays login information
1035 Password
Innovation never stops -- the innovation process of nvisual network visualization platform for Excel import
brew install * 失败,解决方法
正则表达式总结
简单封装 js并应用
idea開發工具常用的插件合集匯總
Ls1046nfs mount file system
我所理解的DRM显示框架
Zzuli:1062 greatest common divisor