<?xml version="1.0"encoding="UTF-8"? ><clientset><server url="192.168.0.180"port="1935"/><rootpath value=""/>"http://www.aaa.com"/>"help.html"/><language value="en"/><theme value="default"/><visiblemarquee value ="true"/><visiblewhitepaper value="true"/><showmemberroomforguest value ="true"/><emotions enabled="true"column="5"autoplay="false"><item name="Birthday"Src="cartoon/movie/birthday.swf"thumb="cartoon/preview/birthday-small.swf"duration=" the"/><item name="Boom"Src="cartoon/movie/boom.swf"thumb="cartoon/preview/boom-small.swf"duration="6"/><item name="Bubble"Src="cartoon/movie/bubble.swf"thumb="cartoon/preview/bubble-small.swf"duration="7.5"/><item name="Cry"Src="cartoon/movie/cry.swf"thumb="cartoon/preview/cry-small.swf"duration="5.4"/><item name="Doggie"Src="cartoon/movie/doggie.swf"thumb="cartoon/preview/doggie-small.swf"duration=" -"/><item name="Greeting"Src="cartoon/movie/greeting.swf"thumb="cartoon/preview/greeting-small.swf"duration="7.4"/><item name="Football"Src="cartoon/movie/football.swf"thumb="cartoon/preview/football-small.swf"duration="2.2"/></emotions ></clientSet> <?$dom=NewDOMDocument ('1.0'); $dom->load ('X.xml'); $em= $dom->getelementsbytagname ('Emotions'); $em= $em->item (0); $items= $em->getelementsbytagname ('Item');foreach($items as$a) {foreach($a->attributes as$b) {if($b->nodevalue=='Birthday') {$a->setattribute ('name','Nbirthday');}}} $t= $dom->createelement ('Item'); $t->setattribute ('name','x'); $t->setattribute ('src','www.sohu.com'); $t->setattribute ('Duration','Duration'); $em-appendchild ($t); $dom->save ('X.xml');?>
PHP modifies and adds XML node attributes