Node.js: How to create XML files

前端 未结 2 835
长情又很酷
长情又很酷 2021-02-03 18:04

Is there a good way to create XML files? For example, like the Builder for Rails (or any other way)?

Thanks

2条回答
  •  孤城傲影
    2021-02-03 18:40

    recent changes to xmlbuilder require root element name passed to create()

    see working example

    var builder = require('xmlbuilder');
    var doc = builder.create('root')
      .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')
    .end({ pretty: true });
    console.log(doc.toString());
    

提交回复
热议问题