这种需求用正则替换比操作xml dom要简便些吧- @echo off
- powershell ^
- $file='测试.xml';$str='^<string name=\"apinfo\"^>993684b8-801d-4b22-825c-db90e14b45a4^</string^>';^
- $str+=\"`r`n\"+'^<string name=\"email\"^>myname123@163.com^</string^>'+\"`r`n\";^
- [IO.File]::ReadAllText($file, [Text.Encoding]::UTF8) -replace '(?=^</map^>)',$str^|^
- out-file ('New'+$file) -enc UTF8
- pause
复制代码
- //&cls&cscript -nologo -e:jscript "%~f0" "测试.xml"&pause&exit
-
- var file=WSH.Arguments(0);
- var arr=[['string','993684b8-801d-4b22-825c-db90e14b45a4','name','apinfo'],['string','myname123@163.com','name','email']];
- var xml=new ActiveXObject('Microsoft.XMLDOM');
- xml.async=false;
- xml.preserveWhiteSpace=true;
- xml.load(file);
- var map=xml.getElementsByTagName('map')[0];
- for(var i=0;i<arr.length;i++){
- var e=xml.createElement(arr[i][0]);
- e.text=arr[i][1];
- e.setAttribute(arr[i][2], arr[i][3]);
- map.appendChild(e);
- }
- xml.save('New_'+file);
复制代码
|