當前位置:才華齋>計算機>php語言>

php修改增加xml結點屬性的程式碼

php語言 閱讀(1.98W)

php修改xml結點屬性,增加xml結點屬性的.程式碼,有需要的朋友,參考下。就跟隨本站小編一起去了解下吧,想了解更多相關資訊請持續關注我們應屆畢業生考試網!

php修改增加xml結點屬性的程式碼

  1、xml檔案

複製程式碼 程式碼示例:

<?xml version="1.0" encoding="UTF-8" ?>

<clientSet>

<server url="" port="1935" />

<rootPath value="" />

<homePath value="" />

<helpPath value="" />

<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/" thumb="cartoon/preview/" duration="15"/>

<item name="Boom" src="cartoon/movie/" thumb="cartoon/preview/" duration="6"/>

<item name="Bubble" src="cartoon/movie/" thumb="cartoon/preview/" duration="7.5"/>

<item name="Cry" src="cartoon/movie/" thumb="cartoon/preview/" duration="5.4"/>

<item name="Doggie" src="cartoon/movie/" thumb="cartoon/preview/" duration="13"/>

<item name="Greeting" src="cartoon/movie/" thumb="cartoon/preview/" duration="7.4"/>

<item name="Football" src="cartoon/movie/" thumb="cartoon/preview/" duration="2.2"/>

</emotions >

</clientSet>

  2、php程式碼

複製程式碼 程式碼示例:

<?

$dom=new DOMDocument('1.0');

$dom->load('');

$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','');

$t->setAttribute('duration','duration');

$em->appendChild($t);

$dom->save('');

?>