Added "xml" module for working with XML documents.
- xml.parse(string|buffer) returns an XMLDoc wrapper object around
XML structure.
- xml.c14n(root_node[, excluding_node]]) canonicalizes root_node and
its children according to https://www.w3.org/TR/xml-c14n, optionally
excluding_node allows to omit from the output a part of the
document.
- xml.exclusiveC14n(root_node[, excluding_node[, withComments [,
prefix_list]]]) canonicalizes root_node and its children
according to https://www.w3.org/TR/xml-exc-c14n/. excluding_node
allows to omit from the output a part of the document
corresponding to the node and its children. withComments
is a boolean and is false by default. When withComments is true
canonicalization corresponds to
http://www.w3.org/2001/10/xml-exc-c14n#WithComments. prefix_list is
an optional string with a space separated namespace prefixes for
namespaces that should also be included into the output.
- XMLDoc an XMLDoc wrapper object around XML structure.
doc.xxx returns the first root tag named "xxx" as XMLNode wrapper
object.
- XMLNode an XMLNode wrapper object around XML tag node.
node.$tag$xxx returns the first child tag named "xxx" as XMLNode
wrapper object.
node.xxx a shorthand syntax for node.$tag$xxx.
node.$tags$xxx? returns an array of all children tags named xxx.
node.$attr$xxx returns an attribute value of xxx.
node.$attrs returns an XMLAttr wrapper object.
node.$name returns the tag name of the node.
node.$ns returns the namespace of the node.
node.$parent returns the parent of the node.
node.$text returns the node's content.
- XMLAttrs an XMLAttrs wrapper object around XML node attributes.
attrs.xxx returns a value of the xxx attribute.
- Example:
const xml = require("xml");
let data = `<note><to b="bar" a= "foo" >Tove</to><from>Jani</from></note>`;
let doc = xml.parse(data);
console.log(doc.note.to.$text) /* 'Tove' */
console.log(doc.note.to.$attr$b) /* 'bar' */
console.log(doc.note.$tags[1].$text) /* 'Jani' */
let dec = new TextDecoder();
let c14n = dec.decode(xml.exclusiveC14n(doc.note));
console.log(c14n) /* '<note><to a="foo" b="bar">Tove</to><from>Jani</from></note>' */
c14n = dec.decode(xml.exclusiveC14n(doc.note.to));
console.log(c14n) /* '<to a="foo" b="bar">Tove</to>' */
c14n = dec.decode(xml.exclusiveC14n(doc.note, doc.note.to /* excluding 'to' */));
console.log(c14n) /* '<note><from>Jani</from></note>' */