# HG changeset patch # User Yaroslav Zhuravlev # Date 1675354935 0 # Node ID 41870b949ac973fe93818de03454a05f1c441908 # Parent 386ba17fac2398fea1375d508e99766b5f873a00 Documented XML module in njs. diff --git a/xml/en/docs/njs/reference.xml b/xml/en/docs/njs/reference.xml --- a/xml/en/docs/njs/reference.xml +++ b/xml/en/docs/njs/reference.xml @@ -9,7 +9,7 @@
+ rev="98">
@@ -1881,7 +1881,7 @@ that represents the input to the derivat - the initial key material for the derivation function: for example, for PBKDF2 it might be a password, imported as a CryptoKey using -сrypto.subtle.importKey(). +сrypto.subtle.importKey(). derivedKeyAlgorithm @@ -5110,6 +5110,216 @@ and should not be used directly.
+ +
+ + +The XML module allows working with XML documents +(0.7.10). +The XML module object is returned by +require('xml'). + + + +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>' */ + + + + + + +parse(string | +Buffer) + +Parses a string or Buffer for an XML document, +returns an +XMLDoc wrapper object + around XML structure. + + +xml.c14n(root_node[, +excluding_node]]) + +Canonicalizes root_node and its children according to +Canonical XML Version 1.1. + + + + +excluding_node + +allows omitting 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 +Exclusive XML +Canonicalization Version 1.0. + + + + +excluding_node + +allows omitting from the output a part of the document +corresponding to the node and its children + + +withComments + +a boolean value, false by default. +If true, canonicalization corresponds to +Exclusive XML +Canonicalization Version 1.0. + + +prefix_list + +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. + + + + +$root + +the root tag as +XMLNode wrapper object + + +doc.xxx + +the first root tag named xxx as +XMLNode wrapper object + + + + + + + +XMLNode + +An XMLNode wrapper object around XML tag node. + + + +node.$tag$xxx + +the first child tag named xxx as +XMLNode wrapper object + + +node.xxx + +a shorthand syntax for +node.$tag$xxx + + +node.$tags$xxx + +an array of all children tags named xxx + + +node.$tags$ + +an array of all children tags + + +node.$attr$xxx + +an attribute value of xxx + + +node.$attrs + +an XMLAttr wrapper object + + +node.$name + +the tag name of the node + + +node.$ns + +the namespace of the node + + +node.$parent + +the parent of the node + + +node.$text + +the node's content + + + + + + + +XMLAttr + +An XMLAttrs wrapper object around XML node attributes. + + + + +attr.xxx + +a value of the xxx attribute + + + + + + + + + + +
+