代码如下:
/*
<기사>
<아이템>
11 content1 2009-10-11 <아이템>
title2 content2 2009-11-11 */
if(!function_exists('l')) {
function l() {
echo '
************ ***********************
';
}
}
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");
}
?>