polotek/libxmljs — pull request #198 by luismalheiro (2013-05-22 11:52:10+00:00)
Title: This change allows to create a text node if a name is not specified to the Element constructor

This change allows to create a text instead of a node when the 'name' argument of the Element constructor is not a string. I hope that it makes sense and can be pulled into the base repository. If you believe I should improve it before, please let me know. Thanks.

See Example:

var libxmljs = require('libxmljs')
var doc = new libxmljs.Document();
var root = doc.node('node1');
root.text('Text 1');
var elem1 = libxmljs.Element(doc, 'node2', 'Text 2');
root.addChild(elem1);
// Text:
var elem2 = libxmljs.Element(doc, null, 'Text 3');
root.addChild(elem2);
// Text:
var elem3 = libxmljs.Element(doc, null, '/Text 4');
root.addChild(elem3);
var elem4 = libxmljs.Element(doc, 'node3', 'Text 5');
root.addChild(elem4);
console.log(doc.toString());

produces:

Text 1Text 2Text 3/Text 4Text 5