美文网首页
php读取xml文件并获取值

php读取xml文件并获取值

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

queryxml.sh

#!/sbin/php -q
<?php
    //eg: ./queryxml.sh /home/etc/application/config/sys_para.xml  paraName

    $fileName = $argv[1];//   /home/etc/application/config/sys_para.xml ;
    $setName  = $argv[2];//  'paraName'        

    if(empty($fileName)){
        echo 'fileName is Empty';
        exit;
    }
    if(empty($setName)){
        echo 'setName 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;
            echo $value;
            break;
        }
    }
?>

相关文章

网友评论

      本文标题:php读取xml文件并获取值

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