我正在使用“xmlbuilder”node.js 模块来创建 xml 文件。我需要创建一个 CDATA 部分,如下所示:
<notestext><![CDATA[{Notes Text}]]></notestext>
我引用了 github link ,但没有找到任何有用的东西。
如何使用“xmlbuilder”node.js 模块在 xml 文件中创建这样的 CDATA 部分?
let builder = require('xmlbuilder', { encoding: 'utf-8' });
let xml = builder.create('Slides');
xml.ele("notestext","<![CDATA[" + element.notes_text + "]]>");
xml.end({ pretty: true });
console.log(xml.toString());
最佳答案
来自 Doc你发布了
CDATA Nodes CDATA nodes are created with the cdata function (can also be abbreviated to dat or d). The value should not include CDATA delimiters
ele.dat('this will be surrounded by CDATA delimiters');
var builder = require('xmlbuilder', { encoding: 'utf-8' });
var xml = builder.create('slides');
xml.ele('notestext').dat('{Notes Text}');
xml.end({
pretty: true,
indent: ' '
});
console.log(xml.toString());
关于javascript - 无法使用 "xmlbuilder"node.js 模块在 XML 中创建 CDATA 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53238406/