Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.89k stars 606 forks source link

Can't get doctype to render #295

Open pessato opened 8 years ago

pessato commented 8 years ago

From @pessato on April 16, 2016 8:21

var fs = require('fs'),
    xml2js = require('xml2js');

var obj = {name: "Super", Surname: "Man", age: 23};

var options = {
    rootName: 'test', 
    doctype: {'ext': 'hello.dtd'},
    xmldec: {'version': '1.0', 'encoding': 'UTF-8'}
};

var builder = new xml2js.Builder(options);
var xml = builder.buildObject(obj);

console.log(xml);

Gives me...

<?xml version="1.0" encoding="UTF-8"?>
<test>
  <name>Super</name>
  <Surname>Man</Surname>
  <age>23</age>
</test>

How can I get...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ext SYSTEM "hello.dtd">
<test>
  <name>Super</name>
  <Surname>Man</Surname>
  <age>23</age>
</test>

Copied from original issue: oozcitak/xmlbuilder-js#123

pessato commented 8 years ago

From @oozcitak on April 18, 2016 8:7

You should take this to xml2js, however if it passes options directly to xmlbuilder than the correct syntax should be:

var options = {
    rootName: 'test', 
    doctype: {'sysID': 'hello.dtd'},
    xmldec: {'version': '1.0', 'encoding': 'UTF-8'}
};

Note sysID instead of ext.

pessato commented 8 years ago

No idea how I've ended up creating this issue here... Apologies and thanks.

pessato commented 8 years ago

Correct me if I'm wrong, however I think the README needs to be updated to reflect the above? i.e.

doctype (default null): optional DTD. Eg. {'sysID': 'hello.dtd'}