-
-
Notifications
You must be signed in to change notification settings - Fork 110
Value Conversion
This page documents string conversion functions used while converting user supplied values to XML nodes. Those functions are passed to the builder while calling the create
and begin
functions:
var xmlbuilder = require('xmlbuilder');
var root = xmlbuilder.create('root', {
stringify: {
name: function(val) {
return 'myns:' + val; // prepend myns: to all names
}
}
});
converts val
to a node name or an attribute name string
converts val
to text node content
converts val
to CDATA node content
converts val
to comment node content
converts val
to raw node content
converts val
to attribute content
converts val
to processing instruction node target
converts val
to processing instruction node value
converts val
to XML version string
converts val
to XML encoding string
converts val
to XML standalone string
converts val
to DocType public identifier
converts val
to DocType system identifier
converts val
to element (!ELEMENT
) node content inside the DTD
converts val
to attribute (!ATTLIST
) node type inside the DTD
converts val
to attribute (!ATTLIST
) node default value inside the DTD
converts val
to entity (!ENTITY
) node value inside the DTD
converts val
to attribute (!NOTATION
) node data inside the DTD
escapes str
to be used in text node value
escapes str
to be used in attribute value
While converting from JS objects, XML attributes and special nodes are recognized with decorator strings. For example, if an object key starts with @
, it will be converted to an XML attribute. Decorators can also be customized by setting stringify
properties below.
When prepended to a JS object key, converts the key-value pair to an attribute.
When prepended to a JS object key, converts the key-value pair to a processing instruction node.
When prepended to a JS object key, converts its value to a text node. Since JS objects cannot contain duplicate keys, multiple text nodes can be created by adding some unique text after each object key. For example:
obj = {
node: {
'#text_1': 'some text',
'#text_2': 'additional text',
'#text_3': 'some more text',
}
}
This also applies to CDATA, comment and raw keys below.
When prepended to a JS object key, converts its value to a CDATA node.
When prepended to a JS object key, converts its value to a comment node.
When prepended to a JS object key, converts its value to a raw text node.