-
-
Notifications
You must be signed in to change notification settings - Fork 107
Builder Options
Ozgur Ozcitak edited this page Mar 15, 2019
·
8 revisions
This page documents the various options that can be used to customize the behavior of the XML builder.
-
versionA version number string:1.0or1.1. This also changes character validation. Defaults to1.0if omitted. -
encodingEncoding declaration, e.g.UTF-8. No encoding declaration will be produced if omitted. -
standalonestandalone document declaration:trueorfalse. No standalone document declaration will be produced if omitted. -
headlesswhether XML declaration and doctype will be included:trueorfalse. Defaults tofalse.
Note: XML declaration can be specified later with the dec function. Also see this wiki page.
builder.create('root')
.dec('1.0', 'UTF-8', true);-
pubIDpublic identifier of the external subset. No default. -
sysIDsystem identifier of the external subset. No default.
Note: If neither pubID nor sysID is given, an external document type definition will not be produced.
Note: A DTD can also be created at a later time by calling doctype from anywhere in the document (can also be abbreviated to dtd). Also see this wiki page.
var dtd = root.dtd('pubID', 'sysID');-
keepNullNodeswhether nodes withnullvalues will be kept or ignored:trueorfalse. Defaults tofalse, which silently ignores nodes withnullvalues. -
keepNullAttributeswhether attributes with null values will be kept or ignored:trueorfalse. Defaults tofalse, which silently ignores attributes withnullvalues. -
ignoreDecoratorswhether decorator strings will be ignored when converting JS objects:trueorfalse. Defaults tofalse. -
separateArrayItemswhether array items are created as separate nodes when passed as an object value:trueorfalse. Defaults tofalse. See this page for an example. -
noDoubleEncodingwhether existing html entities are encoded:trueorfalse. Defaults tofalse. For example, when converting the following JS object:
const root = {
'@att': 'attribute value with # and #'
'#text': 'HTML entities for umlaut are ü and ü.'
}
// with noDoubleEncoding: false (default)
const xmlStr = xml(obj).end({ pretty: true });
// <?xml version="1.0"?>
// <root att="attribute value with &num; and &#35;">
// HTML entities for umlaut are &uuml; and &#252;.'
// </root>
// with noDoubleEncoding: true
const xmlStr = xml(obj, { noDoubleEncoding: true }).end({ pretty: true });
// <?xml version="1.0"?>
// <root att="attribute value with # and #">
// HTML entities for umlaut are ü and ü.'
// </root>-
stringifya set of functions to use for converting values to strings. See this page for value conversion details and decorator strings. -
writerthe default XML writer to use for converting nodes to string. If the default writer is not set, the built-inXMLStringWriterwill be used instead. See this page for information on writers.