码迷,mamicode.com
首页 > Web开发 > 详细

php 读写xml 修改xml

时间:2014-11-25 16:20:22      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   for   on   div   

需要修改的xml

<?xml version="1.0"?>
<config>
    <administration>
        <adminuser>
            <user>
                <id type="autoinc">1</id>
                <name type="username" min="3" max="20">admin</name>
                <passwdmd5 type="passwd" min="4" max="10">21232f297a57a5a743894a0e4a801fc3</passwdmd5>
                <purview type="purview">super</purview>
            </user>
        </adminuser>
    </administration>
</config>

 

用php修改xml的节点

$doc = new DOMDocument; 
$doc->load(‘test.xml‘);
$users = $doc->documentElement->getElementsByTagName(‘user‘);
foreach($users as $user) 
{
    $purviews = $user->getElementsByTagName(‘purview‘);
    $purview = $purviews->item(0);
     
    $tmpNode = $purview->cloneNode();
    $tmpNode->nodeValue = "xxx";   
    $tmpNode = $purview->parentNode->appendChild($tmpNode);
    $purview->parentNode->replaceChild($tmpNode,$purview);
    $doc->save("test1.xml"); 
} 

 

php 读写xml 修改xml

标签:style   blog   io   ar   color   sp   for   on   div   

原文地址:http://www.cnblogs.com/itafter/p/4121112.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!