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);
?>
网友评论