首页 > 代码库 > 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结点属性
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。