php语言

php修改增加xml结点属性的代码

时间:2025-04-10 10:19:39 php语言 我要投稿
  • 相关推荐

php修改增加xml结点属性的代码

  php修改xml结点属性,增加xml结点属性的代码,有需要的朋友,参考下。就跟随百分网小编一起去了解下吧,想了解更多相关信息请持续关注我们应届毕业生考试网!

  1、xml文件

  复制代码 代码示例:

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

  <clientSet>

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

  <rootPath value="" />

  <homePath value="http://www.aaa.com" />

  <helpPath value="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="15"/>

  <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="13"/>

  <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>

  2、php代码

  复制代码 代码示例:

  <?

  $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=='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结点属性的代码】相关文章:

php解析XML文档属性并编辑的代码04-12

php生成sitemap.xml的实例代码06-02

php操作xml入门之xml基本介绍08-13

PHP调用的C代码08-05

PHP代码优化技巧05-29

PHP代码运行流程08-14

php语言字典代码06-08

php分页类代码04-30

PHP实用的代码实例08-12