当前位置:网站首页>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>
*/
?>
边栏推荐
- Go language web development is very simple: use templates to separate views from logic
- Fabric. JS upload local image to canvas background
- Zzuli:1066 character classification statistics
- Gcnet: non - local Networks meet Squeeze excitation Networks and Beyond
- Brew install * failed, solution
- Matplotlib double Y axis + adjust legend position
- 在线音乐播放器app
- 记录sentry的踩坑之路
- php内类名称与类内方法名相同
- Fabric. JS centered element
猜你喜欢
随机推荐
Ls1046nfs mount file system
如何写出好代码 — 防御式编程指南
Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?
1037 Magic Coupon
【论文翻译】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
Fabric. JS iText set italics manually
Pytorch Basics
记录sentry的踩坑之路
File contains vulnerability (I)
I want to understand the swift code before I learn it. I understand it
Software testing learning - day 4
[paper translation] gcnet: non local networks meet squeeze exception networks and beyond
Fabric. JS 3 APIs to set canvas width and height
Technologists talk about open source: This is not just using love to generate electricity
Sliding window on the learning road
Record sentry's path of stepping on the pit
A collection of commonly used plug-ins for idea development tools
来啦~ 使用 EasyExcel 导出时进行数据转换系列新篇章!
Centos8 installation mysql8.0.22 tutorial
Fabric. JS iText superscript and subscript





![[technical notes-08]](/img/52/0aff21b01ba7adbfcdb597d1aa85f9.png)


