1
我想讀取特定的xml標記並更新它。使用節點JS中的fs-extra更新xml文件
這裏是xml文件
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.myapp450442" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>myApp</name>
<description>
An Ionic Framework and Cordova project.
</description>
<author email="[email protected]" href="http://ionicframework.com/">
Ionic Framework Team
</author>
<content src="index.html"/>
<access origin="*"/>
<preference name="webviewbounce" value="false"/>
<preference name="UIWebViewBounce" value="false"/>
<preference name="DisallowOverscroll" value="true"/>
<preference name="android-minSdkVersion" value="16"/>
<preference name="BackupWebStorage" value="none"/>
<feature name="StatusBar">
<param name="ios-package" value="CDVStatusBar" onload="true"/>
</feature>
</widget>
我也跟着上 stack over flow這個類似的問題,但它並沒有爲我工作。
這裏是我用
fs.readFile(configFile, 'utf-8',function(err, data) {
if (err) {
return console.log(err);
}
var name="<name>"+appName+"</name>";
var cursor = "//cursor";
var result = data.replace(/\/\/cursor/,name);
fs.writeFile(configFile, result, 'utf-8', function(err) {
if (err) return console.log(err);
});
fs.writeFile(appIconFile, icon, 'base64', function(err) {
if (err) return console.log(err);
});
});
有人可以告訴我,可能是什麼問題,這裏的代碼?
有沒有更好的npm模塊..?
我可以得到小部件版本..? – Thusithz