我正在尝试'<p>hi</p>'
用“嗨”替换
我的 JavaScript:
var obj = {item:{title: params.title,description: params.text, link: req.headers['origin']+"/blog/blog-description/"+params.blog_id, guid:req.headers['origin']+"/blog/blog-description/"+params.blog_id}};
var xml2js = require('xml2js');
var builder = new xml2js.Builder();
var xml = builder.buildObject(obj);
var modXml = xml.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '');
var modXml = xml.replace(/<(?:.|\n)*?>/gm, '');
var new_text = modXml;
fs.readFile('public/feed.xml', function read(err, data) {
if (err) throw err;
var file_content = data.toString();
var c = file_content.indexOf('</description>');
var position = c + 14;
file_content = file_content.substring(position);
var file = fs.openSync('public/feed.xml','r+');
var bufferedText = new Buffer(new_text+file_content);
fs.writeSync(file, bufferedText, 0, bufferedText.length, position);
fs.close(file);
});
我不知道哪里出了问题,有人可以建议帮助。