美文网首页
php修改xml文件

php修改xml文件

作者: 炽热冰峰 | 来源:发表于2018-09-27 16:56 被阅读0次

modifyxml.sh

#!/sbin/php -q
<?php
    $fileName = $argv[1];//  '/etc/application/config/dpi_para.xml'  
    $setName  = $argv[2];//  'paraName'         
    $setValue = $argv[3];//   'paraValue'      

    if(empty($fileName)){
        echo 'fileName is Empty';
        exit;
    }
    if(empty($setName)){
        echo 'setName is Empty';
        exit;
    }
    if(empty($setValue)){
        echo 'setValue is Empty';
        exit;
    }

    $LIST_TAG  = 'Para';
    $NAME_TAG  = 'Name';
    $VALUE_TAG = 'Value';

    $doc = new DOMDocument();
    $doc->load($fileName);
    
    $paras = $doc->getElementsByTagName($LIST_TAG);
    foreach($paras  as $para){
        $name  = $para->getElementsByTagName($NAME_TAG)->item(0)->nodeValue;
        $value = $para->getElementsByTagName($VALUE_TAG)->item(0)->nodeValue;
        if($name == $setName){
            $para->getElementsByTagName($VALUE_TAG)->item(0)->nodeValue = $setValue;
            echo $name."-".$value."==>".$setValue;
            break;
        }
    }
    $doc->save($fileName);
?>

相关文章

网友评论

      本文标题:php修改xml文件

      本文链接:https://www.haomeiwen.com/subject/gxzeoftx.html