]> git.kaiwu.me - njs.git/commit
Added "xml" module for working with XML documents.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 26 Jan 2023 05:54:47 +0000 (21:54 -0800)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 26 Jan 2023 05:54:47 +0000 (21:54 -0800)
commit9161a840f7226c51d6c1e13621156c238a608761
treea704277192c8fe278764f87bcc5bfbdb9885dcf6
parent4e741bb88f32c8d19a18d5727243d0201f0fce64
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>' */
24 files changed:
auto/libxml2 [new file with mode: 0644]
auto/modules
auto/options
configure
external/njs_xml_module.c [new file with mode: 0644]
nginx/config
nginx/config.make
nginx/ngx_js.c
src/test/njs_unit_test.c
test/harness/compatNjs.js [new file with mode: 0644]
test/harness/compatXml.js [new file with mode: 0644]
test/xml/README.rst [new file with mode: 0644]
test/xml/auth_r.xml [new file with mode: 0644]
test/xml/auth_r_prefix_list.xml [new file with mode: 0644]
test/xml/auth_r_prefix_list_signed.xml [new file with mode: 0644]
test/xml/auth_r_signed.xml [new file with mode: 0644]
test/xml/auth_r_signed2.xml [new file with mode: 0644]
test/xml/auth_r_with_comments_signed.xml [new file with mode: 0644]
test/xml/example.com.crt [new file with mode: 0644]
test/xml/response_assertion_and_message_signed.xml [new file with mode: 0644]
test/xml/response_signed.xml [new file with mode: 0644]
test/xml/response_signed_broken.xml [new file with mode: 0644]
test/xml/response_signed_broken2.xml [new file with mode: 0644]
test/xml/saml_verify.t.js [new file with mode: 0644]