首页 > 代码库 > php修改和增加xml结点属性

php修改和增加xml结点属性

<?xml version="1.0" encoding="UTF-8" ?><clientSet><server url="192.168.0.180" port="1935" /><rootPath value=http://www.mamicode.com/"" /><homePath value=http://www.mamicode.com/"http://www.aaa.com" /><helpPath value=http://www.mamicode.com/"help.html" /><language value=http://www.mamicode.com/"en" /><theme value=http://www.mamicode.com/"default" /><visibleMarquee value = http://www.mamicode.com/"true" /><visibleWhitePaper value=http://www.mamicode.com/"true" /><showMemberRoomForGuest value = http://www.mamicode.com/"true" /><emotions enabled="true" column="5" autoPlay="false"><item name="Birthday" src=http://www.mamicode.com/"cartoon/movie/birthday.swf" thumb="cartoon/preview/birthday-small.swf" duration="15"/><item name="Boom" src=http://www.mamicode.com/"cartoon/movie/boom.swf" thumb="cartoon/preview/boom-small.swf" duration="6"/><item name="Bubble" src=http://www.mamicode.com/"cartoon/movie/bubble.swf" thumb="cartoon/preview/bubble-small.swf" duration="7.5"/><item name="Cry" src=http://www.mamicode.com/"cartoon/movie/cry.swf" thumb="cartoon/preview/cry-small.swf" duration="5.4"/><item name="Doggie" src=http://www.mamicode.com/"cartoon/movie/doggie.swf" thumb="cartoon/preview/doggie-small.swf" duration="13"/><item name="Greeting" src=http://www.mamicode.com/"cartoon/movie/greeting.swf" thumb="cartoon/preview/greeting-small.swf" duration="7.4"/><item name="Football" src=http://www.mamicode.com/"cartoon/movie/football.swf" thumb="cartoon/preview/football-small.swf" duration="2.2"/></emotions ></clientSet> <?$dom=new DOMDocument(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=http://www.mamicode.com/=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修改和增加xml结点属性