# HG changeset patch # User Yaroslav Zhuravlev # Date 1677157514 0 # Node ID ee84a44fa7f7733ecccce5efd80d6e91c6972a96 # Parent 8f50cc590cd7a60a215fc4f046aecfe62faf7fc2 Documented XMLNode API for modification XML docs in njs. Also xml methods sorted alphabetically, some descriptions of existing xml methods were updated. diff -r 8f50cc590cd7 -r ee84a44fa7f7 xml/en/docs/njs/reference.xml --- a/xml/en/docs/njs/reference.xml Tue Feb 14 14:48:36 2023 +0000 +++ b/xml/en/docs/njs/reference.xml Thu Feb 23 13:05:14 2023 +0000 @@ -9,7 +9,7 @@
+ rev="100">
@@ -5115,7 +5115,7 @@ The XML module allows working with XML documents -(0.7.10). +(since 0.7.10). The XML module object is returned by require('xml'). @@ -5152,14 +5152,19 @@ Parses a string or Buffer for an XML document, returns an XMLDoc wrapper object - around XML structure. - - -xml.c14n(root_node[, -excluding_node]]) +representing the parsed XML document. + + +c14n(root_node[, +excluding_node]) Canonicalizes root_node and its children according to Canonical XML Version 1.1. +The root_node can be +XMLNode or +XMLDoc wrapper object +around XML structure. +Returns Buffer object that contains canonicalized output. @@ -5174,18 +5179,26 @@ -xml.exclusiveC14n(root_node[, +exclusiveC14n(root_node[, excluding_node[, withComments [,prefix_list]]]) -Canonicalizes root_node and its children according to +Canonicalizes root_node and its children according to Exclusive XML Canonicalization Version 1.0. +root_node + +is +XMLNode or +XMLDoc wrapper object +around XML structure + + excluding_node allows omitting from the output a part of the document @@ -5198,6 +5211,7 @@ If true, canonicalization corresponds to Exclusive XML Canonicalization Version 1.0. +Returns Buffer object that contains canonicalized output. prefix_list @@ -5211,22 +5225,37 @@ +serialize() + +The same as +xml.c14n() +(since 0.7.11). + + +serializeToString() + +The same as +xml.c14n() +except it returns the result as a string +(since 0.7.11). + + XMLDoc -An XMLDoc wrapper object around XML structure. +An XMLDoc wrapper object around XML structure, +the root node of the document. -$root - -the root tag as -XMLNode wrapper object - - -doc.xxx - -the first root tag named xxx as +doc.$root + +the document's root by its name or undefined + + +doc.abc + +the first root tag named abc as XMLNode wrapper object @@ -5241,56 +5270,136 @@ -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 +node.abc + +the same as +node.$tag$abc + + +node.$attr$abc + +the node's attribute value of abc, +writable +since 0.7.11 + + +node.$attr$abc=xyz + +the same as +node.setAttribute('abc', +xyz) +(since 0.7.11) + + +node.$attrs + +an XMLAttr wrapper object +for all attributes of the node + + +node.$name + +the name of the node + + +node.$ns + +the namespace of the node + + +node.$parent + +the parent node of the current node + + +node.$tag$abc + +the first child tag of the node named abc, +writable +since 0.7.11 + + +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 +node.$tags = [node1, node2, ...] + +the same as +node.removeChildren(); +node.addChild(node1); +node.addChild(node2) +(since 0.7.11). + + +node.$tags$abc + +all children tags named abc of the node, +writable +since 0.7.11 + + +node.$text + +the content of the node, +writable +since 0.7.11 + + +node.$text = 'abc' + +the same as +node.setText('abc') +(since 0.7.11) + + +node.addChild(nd) + +adds XMLNode as a child to node +(since 0.7.11). +nd is recursively copied before adding to the node + + +node.removeAllAttributes() + +removes all attributes of the node +(since 0.7.11) + + +node.removeAttribute(attr_name) + +removes the attribute named attr_name +(since 0.7.11) + + +node.removeChildren(tag_name) + +removes all the children tags named tag_name +(since 0.7.11). +If tag_name is absent, all children tags are removed + + +node.removeText() + +removes the node's text value +(0.7.11) + + +node.setAttribute(attr_name, +value) + +sets a value for an attr_name +(since 0.7.11). +When the value is null, +the attribute named attr_name is deleted + + +node.setText(value) + +sets a text value for the node +(since 0.7.11). +When the value is null, the text of the node is deleted. @@ -5305,9 +5414,9 @@ -attr.xxx - -a value of the xxx attribute +attr.abc + +the attribute value of abc