<?php
/*
<?xml version="1.0" encoding="utf-8"?>
<article>
<item>
<title name="t1">11</title>
<content>content1</content>
<pubdate>2009-10-11</pubdate>
</item>
<item>
<title name="t2">title2</title>
<content>content2</content>
<pubdate>2009-11-11</pubdate>
</item>
</article>
*/
if(!function_exists('l')) {
function l() {
echo '<br/>***********************************<br />';
}
}
if(file_exists('test10_12.xml')) {
$xml = simplexml_load_file('test10_12.xml');
//利用xpath方法查找节点位置
$query = $xml->xpath('//title[@name="t1"]/ancestor::item');
var_dump($query);
l();
//测试在title节点下新增子节点new
$query[0]->title->addchild('new','new');
//测试在title节点下新增属性fuck
$query[0]->title->addattribute('fuck','fuck you');
//测试修改content节点值为hello,world
$query[0]->content = 'hello,world';
//不解释,你懂的
$query[0]->asxml("10.xml");
}
?>
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
网安追踪流程
1.不用代理网民发帖流程:发帖人 → ISP → 服务器托管商 → 服务器网警追踪流程:网监 → 服务器IP →...
[阅读全文]
-
-
-
HTTP状态码大全
转自:https://www.cnblogs.com/lxinxuan/archive/2009/10/22/1...
[阅读全文]
-
-
-
-
网友评论