当前位置:网站首页>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>
*/
?>
边栏推荐
- 在线音乐播放器app
- Gee series: unit 7 remote sensing image classification using GEE [random forest classification]
- Zzuli:1060 numbers in reverse order
- “简单”的无限魔方
- Sliding window on the learning road
- Straighten elements (with transition animation)
- XSS basic content learning (continuous update)
- MySQL foundation --- query (learn MySQL foundation in 1 day)
- [personal test] copy and paste code between VirtualBox virtual machine and local
- 460. LFU cache bidirectional linked list
猜你喜欢

OLED12864 液晶屏

Matplotlib double Y axis + adjust legend position

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

记录sentry的踩坑之路

Balsamiq wireframes free installation

RGB infinite cube (advanced version)

Straighten elements (with transition animation)

Fabric. JS iText sets the color and background color of the specified text

“簡單”的無限魔方

Grbl software: basic knowledge of simple explanation
随机推荐
[technical notes-08]
Technologists talk about open source: This is not just using love to generate electricity
Usage record of vector
Zzuli:1060 numbers in reverse order
ERP management system development and design existing source code
青训营--数据库实操项目
【LeetCode】Day92-盛最多水的容器
centos8安裝mysql8.0.22教程
Fabric. JS upload local image to canvas background
[personal test] copy and paste code between VirtualBox virtual machine and local
小程序跳装到公众号
Storage of data
KMP idea and template code
Simply encapsulate JS and apply it
I want to understand the swift code before I learn it. I understand it
测试 - 用例篇
文件包含漏洞(一)
Huawei Hongmeng OS, is it OK?
Gee: create a new feature and set corresponding attributes
Zzuli:1069 learn from classmate Z