node-opcua-xml2json 2.54.0 → 2.60.0
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/.mocharc.yml +13 -13
- package/LICENSE +20 -20
- package/dist/source/definition_parser.js +9 -9
- package/dist/source/extension_object_parser.d.ts +2 -2
- package/dist/source/extension_object_parser.js +11 -5
- package/dist/source/extension_object_parser.js.map +1 -1
- package/dist/source/fragment_cloner.js +6 -2
- package/dist/source/fragment_cloner.js.map +1 -1
- package/dist/source/fragment_cloner_parser.d.ts +2 -2
- package/dist/source/fragment_cloner_parser.js +0 -1
- package/dist/source/fragment_cloner_parser.js.map +1 -1
- package/dist/source/xml2Json_pojo_tools.js +1 -1
- package/dist/source/xml2Json_pojo_tools.js.map +1 -1
- package/dist/source/xml2json_pojo.js.map +1 -1
- package/package.json +9 -7
- package/pnpm-lock.yaml +4 -4
- package/source/definition_parser.ts +84 -84
- package/source/extension_object_parser.ts +290 -276
- package/source/fragment_cloner.ts +58 -51
- package/source/fragment_cloner_parser.ts +20 -17
- package/source/index.ts +6 -6
- package/source/nodejs/xml2json_fs.ts +43 -43
- package/source/xml2Json_pojo_tools.ts +98 -98
- package/source/xml2json_pojo.ts +26 -27
|
@@ -1,51 +1,58 @@
|
|
|
1
|
-
import { Xml2Json, XmlAttributes, IReaderState } from "./xml2json";
|
|
2
|
-
|
|
3
|
-
interface XmlWriter {
|
|
4
|
-
startElement(elementName: string): this;
|
|
5
|
-
|
|
6
|
-
endElement(): this;
|
|
7
|
-
|
|
8
|
-
writeAttribute(attributeName: string, attributeValue: string | number): this;
|
|
9
|
-
|
|
10
|
-
writeComment(comment: string): this;
|
|
11
|
-
|
|
12
|
-
text(str: string): this;
|
|
13
|
-
}
|
|
14
|
-
const XMLWriter = require("xml-writer");
|
|
15
|
-
|
|
16
|
-
export class InternalFragmentClonerReaderState implements IReaderState {
|
|
17
|
-
private _xw: XmlWriter = new XMLWriter(true);
|
|
18
|
-
public value: any;
|
|
19
|
-
public initLevel
|
|
20
|
-
public engine?: Xml2Json;
|
|
21
|
-
|
|
22
|
-
public _on_startElement(level: number, elementName: string, attrs: XmlAttributes): void {
|
|
23
|
-
this._xw.startElement(elementName);
|
|
24
|
-
for (const [attName, attValue] of Object.entries(attrs)) {
|
|
25
|
-
this._xw.writeAttribute(attName, attValue);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
public _on_endElement(level: number, elementName: string): void {
|
|
29
|
-
this._xw.endElement();
|
|
30
|
-
if (this.initLevel === level) {
|
|
31
|
-
this.value = this._xw.toString();
|
|
32
|
-
this.engine!._demote(this, this.engine!.currentLevel, elementName);
|
|
33
|
-
this.engine = undefined;
|
|
34
|
-
this._on_finish();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
public _on_init(elementName: string, attrs: XmlAttributes, parent: IReaderState, level: number, engine: Xml2Json): void {
|
|
38
|
-
this.engine = engine;
|
|
39
|
-
this.initLevel = level;
|
|
40
|
-
this._xw = new XMLWriter(true);
|
|
41
|
-
this._xw.startElement(elementName);
|
|
42
|
-
for (const [attName, attValue] of Object.entries(attrs)) {
|
|
43
|
-
this._xw.writeAttribute(attName, attValue);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
import { Xml2Json, XmlAttributes, IReaderState } from "./xml2json";
|
|
2
|
+
|
|
3
|
+
interface XmlWriter {
|
|
4
|
+
startElement(elementName: string): this;
|
|
5
|
+
|
|
6
|
+
endElement(): this;
|
|
7
|
+
|
|
8
|
+
writeAttribute(attributeName: string, attributeValue: string | number): this;
|
|
9
|
+
|
|
10
|
+
writeComment(comment: string): this;
|
|
11
|
+
|
|
12
|
+
text(str: string): this;
|
|
13
|
+
}
|
|
14
|
+
const XMLWriter = require("xml-writer");
|
|
15
|
+
|
|
16
|
+
export class InternalFragmentClonerReaderState implements IReaderState {
|
|
17
|
+
private _xw: XmlWriter = new XMLWriter(true);
|
|
18
|
+
public value: any;
|
|
19
|
+
public initLevel = 0;
|
|
20
|
+
public engine?: Xml2Json;
|
|
21
|
+
|
|
22
|
+
public _on_startElement(level: number, elementName: string, attrs: XmlAttributes): void {
|
|
23
|
+
this._xw.startElement(elementName);
|
|
24
|
+
for (const [attName, attValue] of Object.entries(attrs)) {
|
|
25
|
+
this._xw.writeAttribute(attName, attValue);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
public _on_endElement(level: number, elementName: string): void {
|
|
29
|
+
this._xw.endElement();
|
|
30
|
+
if (this.initLevel === level) {
|
|
31
|
+
this.value = this._xw.toString();
|
|
32
|
+
this.engine!._demote(this, this.engine!.currentLevel, elementName);
|
|
33
|
+
this.engine = undefined;
|
|
34
|
+
this._on_finish();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
public _on_init(elementName: string, attrs: XmlAttributes, parent: IReaderState, level: number, engine: Xml2Json): void {
|
|
38
|
+
this.engine = engine;
|
|
39
|
+
this.initLevel = level;
|
|
40
|
+
this._xw = new XMLWriter(true);
|
|
41
|
+
this._xw.startElement(elementName);
|
|
42
|
+
for (const [attName, attValue] of Object.entries(attrs)) {
|
|
43
|
+
this._xw.writeAttribute(attName, attValue);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public _on_finish(): void {
|
|
48
|
+
/** */
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public _on_endElement2(level: number, elementName: string): void {
|
|
52
|
+
/** */
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public _on_text(text: string): void {
|
|
56
|
+
this._xw.text(text);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import { InternalFragmentClonerReaderState } from "./fragment_cloner";
|
|
2
|
-
import { XmlAttributes } from "./xml2json";
|
|
3
|
-
|
|
4
|
-
export class FragmentClonerParser {
|
|
5
|
-
public value: any;
|
|
6
|
-
private _cloneFragment?: InternalFragmentClonerReaderState;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { InternalFragmentClonerReaderState } from "./fragment_cloner";
|
|
2
|
+
import { XmlAttributes } from "./xml2json";
|
|
3
|
+
|
|
4
|
+
export class FragmentClonerParser {
|
|
5
|
+
public value: any;
|
|
6
|
+
private _cloneFragment?: InternalFragmentClonerReaderState;
|
|
7
|
+
private engine?: {
|
|
8
|
+
currentLevel: number;
|
|
9
|
+
_promote: (frag: InternalFragmentClonerReaderState, level: number, elementName: string, attrs: XmlAttributes) => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
public startElement(elementName: string, attrs: XmlAttributes): void {
|
|
13
|
+
this._cloneFragment = new InternalFragmentClonerReaderState();
|
|
14
|
+
this.engine!._promote(this._cloneFragment, this.engine!.currentLevel, elementName, attrs);
|
|
15
|
+
}
|
|
16
|
+
public finish(): void {
|
|
17
|
+
this.value = this._cloneFragment!.value;
|
|
18
|
+
this._cloneFragment!.value = null;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/source/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./xml2json";
|
|
2
|
-
export * from "./fragment_cloner";
|
|
3
|
-
export * from "./xml2json_pojo";
|
|
4
|
-
export * from "./fragment_cloner_parser";
|
|
5
|
-
export * from "./extension_object_parser";
|
|
6
|
-
export * from "./definition_parser";
|
|
1
|
+
export * from "./xml2json";
|
|
2
|
+
export * from "./fragment_cloner";
|
|
3
|
+
export * from "./xml2json_pojo";
|
|
4
|
+
export * from "./fragment_cloner_parser";
|
|
5
|
+
export * from "./extension_object_parser";
|
|
6
|
+
export * from "./definition_parser";
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import { Callback, SimpleCallback, Xml2Json } from "../xml2json";
|
|
3
|
-
|
|
4
|
-
export class Xml2JsonFs extends Xml2Json {
|
|
5
|
-
/**
|
|
6
|
-
* @method parse
|
|
7
|
-
* @async
|
|
8
|
-
* @param xmlFile - the name of the xml file to parse.
|
|
9
|
-
*/
|
|
10
|
-
public parse(xmlFile: string): Promise<any>;
|
|
11
|
-
public parse(xmlFile: string, callback: Callback<any> | SimpleCallback): void;
|
|
12
|
-
public parse(xmlFile: string, callback?: Callback<any> | SimpleCallback): any {
|
|
13
|
-
if (!callback) {
|
|
14
|
-
throw new Error("internal error");
|
|
15
|
-
}
|
|
16
|
-
const readWholeFile = true;
|
|
17
|
-
if (readWholeFile) {
|
|
18
|
-
// slightly faster but require more memory ..
|
|
19
|
-
fs.readFile(xmlFile, (err: Error | null, data: Buffer) => {
|
|
20
|
-
if (err) {
|
|
21
|
-
return callback(err);
|
|
22
|
-
}
|
|
23
|
-
if (data[0] === 0xef && data[1] === 0xbb && data[2] === 0xbf) {
|
|
24
|
-
data = data.slice(3);
|
|
25
|
-
}
|
|
26
|
-
const dataAsString = data.toString();
|
|
27
|
-
const parser = this._prepareParser(callback);
|
|
28
|
-
parser.write(dataAsString);
|
|
29
|
-
parser.end();
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
const Bomstrip = require("bomstrip");
|
|
33
|
-
|
|
34
|
-
const parser = this._prepareParser(callback);
|
|
35
|
-
|
|
36
|
-
fs.createReadStream(xmlFile, { autoClose: true, encoding: "utf8" }).pipe(new Bomstrip()).pipe(parser);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
// tslint:disable:no-var-requires
|
|
41
|
-
const thenify = require("thenify");
|
|
42
|
-
const opts = { multiArgs: false };
|
|
43
|
-
Xml2JsonFs.prototype.parse = thenify.withCallback(Xml2JsonFs.prototype.parse, opts);
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { Callback, SimpleCallback, Xml2Json } from "../xml2json";
|
|
3
|
+
|
|
4
|
+
export class Xml2JsonFs extends Xml2Json {
|
|
5
|
+
/**
|
|
6
|
+
* @method parse
|
|
7
|
+
* @async
|
|
8
|
+
* @param xmlFile - the name of the xml file to parse.
|
|
9
|
+
*/
|
|
10
|
+
public parse(xmlFile: string): Promise<any>;
|
|
11
|
+
public parse(xmlFile: string, callback: Callback<any> | SimpleCallback): void;
|
|
12
|
+
public parse(xmlFile: string, callback?: Callback<any> | SimpleCallback): any {
|
|
13
|
+
if (!callback) {
|
|
14
|
+
throw new Error("internal error");
|
|
15
|
+
}
|
|
16
|
+
const readWholeFile = true;
|
|
17
|
+
if (readWholeFile) {
|
|
18
|
+
// slightly faster but require more memory ..
|
|
19
|
+
fs.readFile(xmlFile, (err: Error | null, data: Buffer) => {
|
|
20
|
+
if (err) {
|
|
21
|
+
return callback(err);
|
|
22
|
+
}
|
|
23
|
+
if (data[0] === 0xef && data[1] === 0xbb && data[2] === 0xbf) {
|
|
24
|
+
data = data.slice(3);
|
|
25
|
+
}
|
|
26
|
+
const dataAsString = data.toString();
|
|
27
|
+
const parser = this._prepareParser(callback);
|
|
28
|
+
parser.write(dataAsString);
|
|
29
|
+
parser.end();
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
const Bomstrip = require("bomstrip");
|
|
33
|
+
|
|
34
|
+
const parser = this._prepareParser(callback);
|
|
35
|
+
|
|
36
|
+
fs.createReadStream(xmlFile, { autoClose: true, encoding: "utf8" }).pipe(new Bomstrip()).pipe(parser);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// tslint:disable:no-var-requires
|
|
41
|
+
const thenify = require("thenify");
|
|
42
|
+
const opts = { multiArgs: false };
|
|
43
|
+
Xml2JsonFs.prototype.parse = thenify.withCallback(Xml2JsonFs.prototype.parse, opts);
|
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export type withPojoLambda = (name: string, pojo: any) => void;
|
|
4
|
-
|
|
5
|
-
export class ReaderState2 extends ReaderStateBase {
|
|
6
|
-
public _stack: any;
|
|
7
|
-
public _pojo: any;
|
|
8
|
-
public _element: any;
|
|
9
|
-
public text: string;
|
|
10
|
-
|
|
11
|
-
public _withPojo: withPojoLambda;
|
|
12
|
-
|
|
13
|
-
private parent?: IReaderState;
|
|
14
|
-
private engine?: Xml2Json;
|
|
15
|
-
private initLevel
|
|
16
|
-
|
|
17
|
-
constructor() {
|
|
18
|
-
super();
|
|
19
|
-
this._pojo = {};
|
|
20
|
-
this._stack = [];
|
|
21
|
-
this._element = {};
|
|
22
|
-
this.text = "";
|
|
23
|
-
this.parent = undefined;
|
|
24
|
-
this._withPojo = (pojo: any) => {
|
|
25
|
-
/* empty */
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public _on_init(elementName: string, attrs: XmlAttributes, parent: IReaderState, level: number, engine: Xml2Json): void {
|
|
30
|
-
this.parent = parent;
|
|
31
|
-
this.engine = engine;
|
|
32
|
-
this.initLevel = level;
|
|
33
|
-
if (this._stack.length === 0) {
|
|
34
|
-
this._pojo = {};
|
|
35
|
-
this._element = this._pojo;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public _on_finish() {
|
|
40
|
-
/* empy */
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public _on_startElement(level: number, elementName: string, attrs: XmlAttributes): void {
|
|
44
|
-
this._stack.push(this._element);
|
|
45
|
-
|
|
46
|
-
if (elementName.match(/^ListOf/)) {
|
|
47
|
-
elementName = elementName.substring(6);
|
|
48
|
-
const elName = lowerFirstLetter(elementName);
|
|
49
|
-
if (this._element instanceof Array) {
|
|
50
|
-
const array: any[] = [];
|
|
51
|
-
this._element.push(array);
|
|
52
|
-
this._element = array;
|
|
53
|
-
} else {
|
|
54
|
-
this._element[elName] = [];
|
|
55
|
-
this._element = this._element[elName];
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
const elName = lowerFirstLetter(elementName);
|
|
59
|
-
if (this._element instanceof Array) {
|
|
60
|
-
const obj = {};
|
|
61
|
-
this._element.push(obj);
|
|
62
|
-
this._element = obj;
|
|
63
|
-
} else {
|
|
64
|
-
this._element[elName] = {};
|
|
65
|
-
this._element = this._element[elName];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public _on_endElement2(level: number, elementName: string): void {
|
|
71
|
-
/* empty */
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public _on_endElement(level: number, elementName: string): void {
|
|
75
|
-
this._element = this._stack.pop();
|
|
76
|
-
if (this.text.length > 0 && this._element) {
|
|
77
|
-
const elName = lowerFirstLetter(elementName);
|
|
78
|
-
this._element[elName] = this.text;
|
|
79
|
-
// this.engine!._pojo = this._pojo;
|
|
80
|
-
} else {
|
|
81
|
-
const elName = lowerFirstLetter(elementName);
|
|
82
|
-
if (this.initLevel === level) {
|
|
83
|
-
if (this._withPojo) {
|
|
84
|
-
if (this.text.length) {
|
|
85
|
-
this._withPojo.call(null, elName, this.text);
|
|
86
|
-
} else {
|
|
87
|
-
this._withPojo.call(null, elName, this._pojo);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
this.text = "";
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public _on_text(text: string): void {
|
|
96
|
-
this.text = text;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
1
|
+
import { lowerFirstLetter } from "node-opcua-utils";
|
|
2
|
+
import { IReaderState, ReaderStateBase, Xml2Json, XmlAttributes } from "./xml2json";
|
|
3
|
+
export type withPojoLambda = (name: string, pojo: any) => void;
|
|
4
|
+
|
|
5
|
+
export class ReaderState2 extends ReaderStateBase {
|
|
6
|
+
public _stack: any;
|
|
7
|
+
public _pojo: any;
|
|
8
|
+
public _element: any;
|
|
9
|
+
public text: string;
|
|
10
|
+
|
|
11
|
+
public _withPojo: withPojoLambda;
|
|
12
|
+
|
|
13
|
+
private parent?: IReaderState;
|
|
14
|
+
private engine?: Xml2Json;
|
|
15
|
+
private initLevel = 0;
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this._pojo = {};
|
|
20
|
+
this._stack = [];
|
|
21
|
+
this._element = {};
|
|
22
|
+
this.text = "";
|
|
23
|
+
this.parent = undefined;
|
|
24
|
+
this._withPojo = (pojo: any) => {
|
|
25
|
+
/* empty */
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public _on_init(elementName: string, attrs: XmlAttributes, parent: IReaderState, level: number, engine: Xml2Json): void {
|
|
30
|
+
this.parent = parent;
|
|
31
|
+
this.engine = engine;
|
|
32
|
+
this.initLevel = level;
|
|
33
|
+
if (this._stack.length === 0) {
|
|
34
|
+
this._pojo = {};
|
|
35
|
+
this._element = this._pojo;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public _on_finish(): void {
|
|
40
|
+
/* empy */
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public _on_startElement(level: number, elementName: string, attrs: XmlAttributes): void {
|
|
44
|
+
this._stack.push(this._element);
|
|
45
|
+
|
|
46
|
+
if (elementName.match(/^ListOf/)) {
|
|
47
|
+
elementName = elementName.substring(6);
|
|
48
|
+
const elName = lowerFirstLetter(elementName);
|
|
49
|
+
if (this._element instanceof Array) {
|
|
50
|
+
const array: any[] = [];
|
|
51
|
+
this._element.push(array);
|
|
52
|
+
this._element = array;
|
|
53
|
+
} else {
|
|
54
|
+
this._element[elName] = [];
|
|
55
|
+
this._element = this._element[elName];
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
const elName = lowerFirstLetter(elementName);
|
|
59
|
+
if (this._element instanceof Array) {
|
|
60
|
+
const obj = {};
|
|
61
|
+
this._element.push(obj);
|
|
62
|
+
this._element = obj;
|
|
63
|
+
} else {
|
|
64
|
+
this._element[elName] = {};
|
|
65
|
+
this._element = this._element[elName];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public _on_endElement2(level: number, elementName: string): void {
|
|
71
|
+
/* empty */
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public _on_endElement(level: number, elementName: string): void {
|
|
75
|
+
this._element = this._stack.pop();
|
|
76
|
+
if (this.text.length > 0 && this._element) {
|
|
77
|
+
const elName = lowerFirstLetter(elementName);
|
|
78
|
+
this._element[elName] = this.text;
|
|
79
|
+
// this.engine!._pojo = this._pojo;
|
|
80
|
+
} else {
|
|
81
|
+
const elName = lowerFirstLetter(elementName);
|
|
82
|
+
if (this.initLevel === level) {
|
|
83
|
+
if (this._withPojo) {
|
|
84
|
+
if (this.text.length) {
|
|
85
|
+
this._withPojo.call(null, elName, this.text);
|
|
86
|
+
} else {
|
|
87
|
+
this._withPojo.call(null, elName, this._pojo);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
this.text = "";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public _on_text(text: string): void {
|
|
96
|
+
this.text = text;
|
|
97
|
+
}
|
|
98
|
+
}
|
package/source/xml2json_pojo.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import { IReaderState, ReaderState, ReaderStateParser, Xml2Json, XmlAttributes } from "./xml2json";
|
|
2
|
-
import { ReaderState2, withPojoLambda } from "./xml2Json_pojo_tools";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
1
|
+
import { IReaderState, ReaderState, ReaderStateParser, Xml2Json, XmlAttributes } from "./xml2json";
|
|
2
|
+
import { ReaderState2, withPojoLambda } from "./xml2Json_pojo_tools";
|
|
3
|
+
|
|
4
|
+
const json_extractor: ReaderState2 = new ReaderState2();
|
|
5
|
+
export const json_parser: ReaderStateParser = {
|
|
6
|
+
init(this: IReaderState, elementName: string, attrs: XmlAttributes, parent: IReaderState, engine: Xml2Json) {
|
|
7
|
+
json_extractor._on_init(elementName, attrs, parent, 0, engine);
|
|
8
|
+
},
|
|
9
|
+
finish(this: any) {
|
|
10
|
+
this.parent._pojo = json_extractor._pojo;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function startPojo(pThis: ReaderState, elementName: string, attrs: XmlAttributes, withPojo: withPojoLambda): void {
|
|
15
|
+
pThis.engine!._promote(json_extractor, pThis.engine!.currentLevel, elementName, attrs);
|
|
16
|
+
json_extractor._withPojo = (name: string, pojo: any) => {
|
|
17
|
+
withPojo(name, pojo);
|
|
18
|
+
pThis.engine!._demote(json_extractor, pThis.engine!.currentLevel, elementName);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class Xml2JsonPojo extends Xml2Json {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(json_extractor as ReaderStateParser);
|
|
25
|
+
}
|
|
26
|
+
}
|