All notable changes to this project are documented in this file. This project adheres to Semantic Versioning.
end()
with arguments no longer overwrites writer options. See #120.openNode
and closeNode
functions to writer. See #193.elEscape
to textEscape
in XMLStringifier
.skipNullAttributes
option. null
attributes are now skipped by default. Added the keepNullAttributes
option in case someone needs the old behavior.skipNullNodes
option. null
nodes are now skipped by default. Added the keepNullNodes
option in case someone needs the old behavior.undefined
values are now skipped when converting JS objects.eleName
-> name
attName
-> name
eleText
-> text
attribute
function in the writer. See #196.openAttribute
and closeAttribute
functions to writer. See #196.nodeType
and writerState
properties.#text
decorator would not be correctly converted. See #171.text
property to value
in comment and cdata nodes to unify the API.doctype
function to prevent name clash with DOM implementation. Use the dtd
function instead.attributes
property to attribs
to prevent name clash with DOM property with the same name.skipNullNodes
was set. See #187.skipNullNodes
option to skip nodes with null values. See #158.spacebeforeslash
writer option accepts true
as well as space char(s).spacebeforeslash
writer option can now be used with XML fragments.spacebeforeslash
writer option to add a space character before closing tags of empty elements. See
#157.Added the callback option to the begin
export function. When used with a
callback function, the XML document will be generated in chunks and each chunk
will be passed to the supplied function. In this mode, begin
uses a different
code path and the builder should use much less memory since the entire XML tree
is not kept. There are a few drawbacks though. For example, traversing the document
tree or adding attributes to a node after it is written is not possible. It is
also not possible to remove nodes or attributes.
var result = '';
builder.begin(function(chunk) { result += chunk; })
.dec()
.ele('root')
.ele('xmlbuilder').up()
.end();
Replaced native Object.assign
with lodash.assign
to support old JS engines. See #111.
begin
export function. See the wiki for details.commentBefore
, commentAfter
, instructionBefore
and instructionAfter
functions for this purpose.Processing instructions are now created as regular nodes. This is a major breaking change if you are using processing instructions. Previously processing instructions were inserted before their parent node. After this change processing instructions are appended to the children of the parent node. Note that it is not currently possible to insert processing instructions before or after the root element.
root.ele('node').ins('pi');
// pre-v7
<?pi?><node/>
// v7
<node><?pi?></node>
XMLStringWriter
class which can be accessed by the stringWriter(options)
function exported by the module. An XMLStreamWriter
is also added which outputs the XML document to a writable stream. A stream writer can be created by calling the streamWriter(stream, options)
function exported by the module. Both classes are heavily customizable and the details are added to the wiki. It is also possible to write an XML writer from scratch and use it when calling end()
on the XML document.lower
, upper
, camel
, kebab
and snake
.allowEmpty
option to end()
. When this option is set, empty elements are not self-closed.]]>
in CDATA is now automatically replaced with ]]]]><![CDATA[>
.noDoubleEncoding
option to create()
to control whether existing html entities are encoded.Added the separateArrayItems
option to create()
to control how arrays are handled when converting from objects. e.g.
root.ele({ number: [ "one", "two" ]});
// with separateArrayItems: true
<number>
<one/>
<two/>
</number>
// with separateArrayItems: false
<number>one</number>
<number>two</number>
#list
decorator. Array items are now created as child nodes by default.#list
decorator ignores empty arrays.\r
, \n
and \t
in attribute values without escaping. See #86.isArray
instead of lodash.XMLNode
constructor overwrote the super class parent.offset
option to toString()
for use in XML fragments.ext
option from create()
.att()
and ins()
.clone
includes attributes.?
.create()
and element()
accept JS object to fully build the document.nod()
and n()
aliases for node()
.convertAttChar
decorator to convertAttKey
.begin()
function. create()
begins the document by creating the root node..npmignore
.begin()
calls in favor of XMLBuilder
constructor.end()
function. end()
is a convenience over doc().toString()
.XMLBuilder
constructor to allow the name of the root element and XML prolog to be defined in one line.begin()
.package.json
in previous releases.importXMLBuilder()
.element()
.root()
on the document element returns the root element.XMLBuilder
no longer extends XMLFragment
.doc()
to return the document element.up()
's older behavior to break.root()
function.package.json
bugs link to url
from web
.create()
function to return a new instance. This allows multiple builder instances to be constructed.u()
function so that it now correctly calls up()
.element()
so that attributes
and text
can be passed interchangeably.ele()
accepts element text.attributes()
now overrides existing attributes if passed the same attribute name.text()
and cdata()
now return parent element.package.json
..npmignore
.begin()
.begin()
.builder()
function from main module.package.json
.element()
expands nested arrays.up()
, build()
and prolog()
functions.