本文介绍了Node.js:如何创建 XML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有好的方法来创建 XML 文件?例如,像 Builder for Rails(或任何其他方式)?
Is there a good way to create XML files? For example, like the Builder for Rails (or any other way)?
谢谢
推荐答案
它看起来像 xmlbuilder-js 库可能会为你做这件事.如果你安装了 npm,你可以npm install xmlbuilder
.
It looks like the xmlbuilder-js library may do this for you. If you have npm installed, you can npm install xmlbuilder
.
它会让你这样做(取自他们的例子):
It will let you do this (taken from their example):
var builder = require('xmlbuilder');
var doc = builder.create('root');
doc.ele('xmlbuilder')
.att('for', 'node-js')
.ele('repo')
.att('type', 'git')
.txt('git://github.com/oozcitak/xmlbuilder-js.git')
.up()
.up()
.ele('test')
.txt('complete');
console.log(doc.toString({ pretty: true }));
这将导致:
<root>
<xmlbuilder for="node-js">
<repo type="git">git://github.com/oozcitak/xmlbuilder-js.git</repo>
</xmlbuilder>
<test>complete</test>
</root>
这篇关于Node.js:如何创建 XML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!