Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
📃 XML parser/stringifier with no dependencies.
Functions
Helper to create a CDATA node.
Helper to create a comment node.
Parse a XML string into an object.
Stringify an xml_document object into a XML string.
Type Aliases
XML parser parse_options.clean
- attributes: boolean
Remove attributes from result.
- comments: boolean
Remove comments from result.
- doctype: boolean
Remove XML doctype from result.
- instructions: boolean
Remove XML processing instructions from result.
XML parser parse_options.flatten
- attributes: boolean
If node only contains attributes values (i.e. with key starting with
@), it'll be flattened as a regular object without@prefixes. - empty: boolean
If node does not contains any attribute or text, it'll be flattened to
null(defaults totrue). - text: boolean
If node only contains a
#textvalue, it'll be flattened as a string (defaults totrue).
XML stringifier stringify_options.format
Nullable type.
XML parser options.
- clean: clean_options
Remove elements from result.
- flatten: flatten_options
Flatten result depending on node content.
- mode: "xml" | "html"
Parsing mode. Using
htmlis more permissive and will not throw on some invalid XML syntax. Mainly unquoted attributes will be supported and not properly closed tags will be accepted. - revive: revive_options
Revive result.
Synchronous reader.
- readSync(buffer: Uint8Array): Nullable<number>
Read synchronously some data into a buffer and returns the number of bytes read.
XML stringifier stringify_options.replace
- custom: (args: { name: string; key: Nullable<string>; value: Nullable<string>; node: Readonly<xml_node>; }) => unknown
Custom replacer (this is applied after other revivals). When it is applied on an attribute,
keyandvaluewill be given. When it is applied on a node, bothkeyandvaluewill benull. Returnundefinedto delete either the attribute or the tag. - entities: boolean
Force escape all XML entities. By default, only the ones that would break the XML structure are escaped.
XML parser parse_options.revive
- booleans: boolean
Revive booleans (matching
/^(?:[Tt]rue|[Ff]alse)$/). - custom: reviver
Custom reviver (this is applied after other revivals). When it is applied on an attribute,
keyandvaluewill be given. When it is applied on a node, bothkeyandvaluewill benull. Returnundefinedto delete either the attribute or the tag. - entities: boolean
Revive XML entities (defaults to
true). Automatically unescape XML entities and replace common entities with their respective characters. - numbers: boolean
Revive finite numbers. Note that the version of the XML prolog is always treated as a string to avoid breaking documents.
- trim: boolean
Trim texts (this is applied before other revivals, defaults to
true). It honorsxml:space="preserve"attribute.
Custom XML parser reviver. It can be used to change the way some nodes are parsed.
XML stringifier options.
& { @version: string; @standalone: string; }
A laxer type for what can be stringified. We won’t ever create this, but we’ll accept it.
& { [@version]?: `1.${number}`; [@encoding]?: string; [@standalone]?: "yes" | "no"; [#doctype]?: xml_node; [#instructions]?: { [key: string]: xml_node | Array<xml_node>; }; }
XML document.
XML node.