background image
$attr_info = $item->getAttribute('info');
echo "<pre>Object:$attr_obj;Info:$attr_info;Value:{$item->n
odeValue}</pre>";
$item->setAttribute('count',1);//添加新的属性 count=1
}
$dom->save('./t.xml');//保存修改
看一下提取到的值:
Object:power;Info:power is shutdown;Value:PHP0
Object:memcache;Info:memcache used than 90%;Value:PHP1
Object:cpu;Info:cpu used than 95%;Value:PHP2
Object:disk;Info:disk is removed;Value:PHP3
再看一下现在的
t.xml 文件的内容,count 属性已经添加上。
<?xml version="1.0"?>
<EventList>
<event obj="power" info="power is shutdown" count="1">PHP0</e
vent>
<event obj="memcache" info="memcache used than 90%" count="1"
>PHP1</event>
<event obj="cpu" info="cpu used than 95%" count="1">PHP2</eve
nt>
<event obj="disk" info="disk is removed" count="1">PHP3</even
t>
</EventList>
修改节点属性
&节点值
以上一节中的
t.xml 文件为操作对象,修改一下 obj 属性是 cpu 的节点的 count 值,新的
值为
count+1。
/*
* 修改某一个节点的属性和值
*/