xml-twig 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/test.js +2 -2
- package/twig.js +7 -11
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -2,10 +2,10 @@ const fs = require('fs');
|
|
|
2
2
|
const twig = require('./twig.js');
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const parser = twig.createParser({ tag: twig.Any, function: anyHandler }, { method: "sax" });
|
|
6
6
|
//const parser = twig.createParser({ tag: twig.Any, function: anyHandler }, { method: "expat" });
|
|
7
7
|
//const parser = twig.createParser({ tag: twig.Any, function: anyHandler }, { method: "saxophone" });
|
|
8
|
-
|
|
8
|
+
fs.createReadStream(`${__dirname}/samples/bookstore.xml`).pipe(parser);
|
|
9
9
|
//fs.createReadStream(`${__dirname}/samples/breakfast-menu.xml`).pipe(parser);
|
|
10
10
|
|
|
11
11
|
//const parser = twig.createParser({ tag: twig.Any, function: nsHandler }, { method: "sax", xmlns: true });
|
package/twig.js
CHANGED
|
@@ -483,8 +483,6 @@ function reset() {
|
|
|
483
483
|
current = undefined;
|
|
484
484
|
}
|
|
485
485
|
|
|
486
|
-
let closeXMLWriterElement = true;
|
|
487
|
-
|
|
488
486
|
/**
|
|
489
487
|
* Generic class modeling a XML Node
|
|
490
488
|
* @class Twig
|
|
@@ -766,7 +764,7 @@ class Twig {
|
|
|
766
764
|
* @returns {string} The XML-Tree which is currently available in RAM - no valid XML Structure
|
|
767
765
|
*/
|
|
768
766
|
debug = function () {
|
|
769
|
-
return this.root().writer(true,
|
|
767
|
+
return this.root().writer(true, true).output;
|
|
770
768
|
};
|
|
771
769
|
|
|
772
770
|
/**
|
|
@@ -774,17 +772,16 @@ class Twig {
|
|
|
774
772
|
* @param {external:XMLWriter} xw - The writer object
|
|
775
773
|
* @param {Twig[]} childArray - Array of child elements
|
|
776
774
|
*/
|
|
777
|
-
#addChild = function (xw, childArray,
|
|
775
|
+
#addChild = function (xw, childArray, cur, debug) {
|
|
778
776
|
for (let elt of childArray) {
|
|
779
777
|
xw.startElement(elt.name);
|
|
780
778
|
for (let [key, val] of Object.entries(elt.attributes))
|
|
781
779
|
xw.writeAttribute(key, val);
|
|
782
780
|
if (elt.text !== null)
|
|
783
781
|
xw.text(elt.text);
|
|
784
|
-
this.#addChild(xw, elt.children(),
|
|
785
|
-
if (elt === startElement) closeXMLWriterElement = false;
|
|
782
|
+
this.#addChild(xw, elt.children(), elt, debug);
|
|
786
783
|
}
|
|
787
|
-
if (
|
|
784
|
+
if (!debug || Object.isSealed(cur)) xw.endElement();
|
|
788
785
|
};
|
|
789
786
|
|
|
790
787
|
/**
|
|
@@ -792,18 +789,17 @@ class Twig {
|
|
|
792
789
|
* @param {?boolean|string|external:XMLWriter} par - `true` or intention character or an already created XMLWriter
|
|
793
790
|
* @returns {external:XMLWriter}
|
|
794
791
|
*/
|
|
795
|
-
writer = function (par,
|
|
792
|
+
writer = function (par, debug) {
|
|
796
793
|
const XMLWriter = require('xml-writer');
|
|
797
794
|
let xw = par instanceof XMLWriter ? par : new XMLWriter(par);
|
|
798
|
-
closeXMLWriterElement = true
|
|
799
795
|
|
|
800
796
|
xw.startElement(this.#name);
|
|
801
797
|
for (let [key, val] of Object.entries(this.#attributes))
|
|
802
798
|
xw.writeAttribute(key, val);
|
|
803
799
|
if (this.#text !== null)
|
|
804
800
|
xw.text(this.#text);
|
|
805
|
-
this.#addChild(xw, this.#children,
|
|
806
|
-
if (
|
|
801
|
+
this.#addChild(xw, this.#children, this, debug);
|
|
802
|
+
if (!debug || Object.isSealed(this)) xw.endElement();
|
|
807
803
|
return xw;
|
|
808
804
|
};
|
|
809
805
|
|