-
-
Notifications
You must be signed in to change notification settings - Fork 107
Builder Options
Ozgur Ozcitak edited this page Mar 26, 2020
·
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. When set totrue,nullwill be treated as an empty string. -
keepNullAttributeswhether attributes with null values will be kept or ignored:trueorfalse. Defaults tofalse, which silently ignores attributes withnullvalues. When set totrue,nullwill be treated as an empty string. -
ignoreDecoratorswhether decorator strings will be ignored when converting JS objects:trueorfalse. Defaults tofalse. See this page for a list of decorator strings. -
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 = builder.create(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 = builder.create(obj, { noDoubleEncoding: true }).end({ pretty: true });
// <?xml version="1.0"?>
// <root att="attribute value with # and #">
// HTML entities for umlaut are ü and ü.'
// </root>-
noValidationwhether XML character validation will be disabled:trueorfalse. Defaults tofalse. -
invalidCharReplacementsets a character to replace invalid characters in input strings. Defaults toundefined. Note that setting this option also disables character validation. See XML 1.0, §2.2 Characters and XML 1.1, §2.2 Characters for valid and invalid character definitions.
const obj = {
'node\x00': 'text\x08content'
}
const xmlStr = builder.create(obj, { invalidCharReplacement: '' }).end({ pretty: true });
// <?xml version="1.0"?>
// <node>textcontent</node>or using a replacement function:
const obj = {
'node\x00': 'text\x08content'
}
const options = {
invalidCharReplacement: (c) => c === '\x00' ? '' : '_'
};
const xmlStr = builder.create(obj, options).end({ pretty: true });
// <?xml version="1.0"?>
// <node>text_content</node>-
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.