【发布时间】:2016-02-03 14:51:18
【问题描述】:
我想读取特定的 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="hi@ionicframework" 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 模块..?
【问题讨论】:
标签: javascript xml node.js fs