当前位置:网站首页>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>
*/
?>
边栏推荐
- 【技术随记-08】
- Alibaba: open source and self-developed liquid cooling data center technology
- Fabric. JS iText set italics manually
- Fabric. JS iText superscript and subscript
- How matlab marks' a 'in the figure and how matlab marks points and solid points in the figure
- 运动健身的一些心得经验
- Basic use of form
- 生成二维码
- Fabric. JS basic brush
- 记录sentry的踩坑之路
猜你喜欢
数理统计与机器学习
2022-2-14 learning xiangniuke project - Section 6 displays login information
Importation de studio visuel
6. Network - Foundation
Gee series: unit 8 time series analysis in Google Earth engine [time series]
[personal test] copy and paste code between VirtualBox virtual machine and local
all3dp.com网站中全部Arduino项目(2022.7.1)
ThreadLocal memory leak
青训营--数据库实操项目
Principle and implementation of parallax effect
随机推荐
Thread pool overview
KMP idea and template code
2022-2-14 learning xiangniuke project - Section 6 displays login information
Fabric. JS iText superscript and subscript
如何写出好代码 — 防御式编程指南
Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
Practice C language advanced address book design
简单封装 js并应用
OLED12864 液晶屏
数据挖掘方向研究生常用网站
A collection of commonly used plug-ins for idea development tools
Fabric. JS upload local image to canvas background
Balsamiq wireframes free installation
Record sentry's path of stepping on the pit
软件测试基础篇
Storage of data
Zzuli:1068 binary number
Gee: create a new feature and set corresponding attributes
软件测试答疑篇
kmp思想及模板代码