@loaders.gl/xml 3.3.0-alpha.8
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/LICENSE +41 -0
- package/README.md +5 -0
- package/dist/dist.min.js +2966 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +20 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/parse-xml.js +28 -0
- package/dist/es5/lib/parse-xml.js.map +1 -0
- package/dist/es5/lib/parser/xml-parser.js +139 -0
- package/dist/es5/lib/parser/xml-parser.js.map +1 -0
- package/dist/es5/sax-ts/sax.js +1389 -0
- package/dist/es5/sax-ts/sax.js.map +1 -0
- package/dist/es5/xml-loader.js +53 -0
- package/dist/es5/xml-loader.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/parse-xml.js +22 -0
- package/dist/esm/lib/parse-xml.js.map +1 -0
- package/dist/esm/lib/parser/xml-parser.js +111 -0
- package/dist/esm/lib/parser/xml-parser.js.map +1 -0
- package/dist/esm/sax-ts/sax.js +1311 -0
- package/dist/esm/sax-ts/sax.js.map +1 -0
- package/dist/esm/xml-loader.js +23 -0
- package/dist/esm/xml-loader.js.map +1 -0
- package/package.json +44 -0
- package/src/bundle.ts +4 -0
- package/src/index.ts +11 -0
- package/src/lib/parse-xml.ts +30 -0
- package/src/lib/parser/xml-parser.ts +115 -0
- package/src/sax-ts/sax.ts +1569 -0
- package/src/xml-loader.ts +38 -0
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,2966 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
9
|
+
var __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
12
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
13
|
+
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
|
+
};
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
__markAsModule(target);
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, module, desc) => {
|
|
21
|
+
if (module && typeof module === "object" || typeof module === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(module))
|
|
23
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
24
|
+
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
|
+
};
|
|
28
|
+
var __toModule = (module) => {
|
|
29
|
+
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/sax-ts/sax.ts
|
|
33
|
+
var DEFAULT_SAX_EVENTS, DEFAULT_SAX_PARSER_OPTIONS, EVENTS, BUFFERS, nameStart, nameBody, entityStart, entityBody, ENTITIES, SAX, SAXParser;
|
|
34
|
+
var init_sax = __esm({
|
|
35
|
+
"src/sax-ts/sax.ts"() {
|
|
36
|
+
DEFAULT_SAX_EVENTS = {
|
|
37
|
+
ontext: () => {
|
|
38
|
+
},
|
|
39
|
+
onprocessinginstruction: () => {
|
|
40
|
+
},
|
|
41
|
+
onsgmldeclaration: () => {
|
|
42
|
+
},
|
|
43
|
+
ondoctype: () => {
|
|
44
|
+
},
|
|
45
|
+
oncomment: () => {
|
|
46
|
+
},
|
|
47
|
+
onopentagstart: () => {
|
|
48
|
+
},
|
|
49
|
+
onattribute: () => {
|
|
50
|
+
},
|
|
51
|
+
onopentag: () => {
|
|
52
|
+
},
|
|
53
|
+
onclosetag: () => {
|
|
54
|
+
},
|
|
55
|
+
onopencdata: () => {
|
|
56
|
+
},
|
|
57
|
+
oncdata: () => {
|
|
58
|
+
},
|
|
59
|
+
onclosecdata: () => {
|
|
60
|
+
},
|
|
61
|
+
onerror: () => {
|
|
62
|
+
},
|
|
63
|
+
onend: () => {
|
|
64
|
+
},
|
|
65
|
+
onready: () => {
|
|
66
|
+
},
|
|
67
|
+
onscript: () => {
|
|
68
|
+
},
|
|
69
|
+
onopennamespace: () => {
|
|
70
|
+
},
|
|
71
|
+
onclosenamespace: () => {
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
DEFAULT_SAX_PARSER_OPTIONS = {
|
|
75
|
+
...DEFAULT_SAX_EVENTS,
|
|
76
|
+
strict: false,
|
|
77
|
+
MAX_BUFFER_LENGTH: 64 * 1024,
|
|
78
|
+
lowercase: false,
|
|
79
|
+
lowercasetags: false,
|
|
80
|
+
noscript: false,
|
|
81
|
+
strictEntities: false,
|
|
82
|
+
xmlns: void 0,
|
|
83
|
+
position: void 0,
|
|
84
|
+
trim: void 0,
|
|
85
|
+
normalize: void 0
|
|
86
|
+
};
|
|
87
|
+
EVENTS = [
|
|
88
|
+
"text",
|
|
89
|
+
"processinginstruction",
|
|
90
|
+
"sgmldeclaration",
|
|
91
|
+
"doctype",
|
|
92
|
+
"comment",
|
|
93
|
+
"opentagstart",
|
|
94
|
+
"attribute",
|
|
95
|
+
"opentag",
|
|
96
|
+
"closetag",
|
|
97
|
+
"opencdata",
|
|
98
|
+
"cdata",
|
|
99
|
+
"closecdata",
|
|
100
|
+
"error",
|
|
101
|
+
"end",
|
|
102
|
+
"ready",
|
|
103
|
+
"script",
|
|
104
|
+
"opennamespace",
|
|
105
|
+
"closenamespace"
|
|
106
|
+
];
|
|
107
|
+
BUFFERS = [
|
|
108
|
+
"comment",
|
|
109
|
+
"sgmlDecl",
|
|
110
|
+
"textNode",
|
|
111
|
+
"tagName",
|
|
112
|
+
"doctype",
|
|
113
|
+
"procInstName",
|
|
114
|
+
"procInstBody",
|
|
115
|
+
"entity",
|
|
116
|
+
"attribName",
|
|
117
|
+
"attribValue",
|
|
118
|
+
"cdata",
|
|
119
|
+
"script"
|
|
120
|
+
];
|
|
121
|
+
nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
|
|
122
|
+
nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
|
|
123
|
+
entityStart = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
|
|
124
|
+
entityBody = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;
|
|
125
|
+
ENTITIES = {
|
|
126
|
+
amp: "&",
|
|
127
|
+
gt: ">",
|
|
128
|
+
lt: "<",
|
|
129
|
+
quot: '"',
|
|
130
|
+
apos: "'",
|
|
131
|
+
AElig: 198,
|
|
132
|
+
Aacute: 193,
|
|
133
|
+
Acirc: 194,
|
|
134
|
+
Agrave: 192,
|
|
135
|
+
Aring: 197,
|
|
136
|
+
Atilde: 195,
|
|
137
|
+
Auml: 196,
|
|
138
|
+
Ccedil: 199,
|
|
139
|
+
ETH: 208,
|
|
140
|
+
Eacute: 201,
|
|
141
|
+
Ecirc: 202,
|
|
142
|
+
Egrave: 200,
|
|
143
|
+
Euml: 203,
|
|
144
|
+
Iacute: 205,
|
|
145
|
+
Icirc: 206,
|
|
146
|
+
Igrave: 204,
|
|
147
|
+
Iuml: 207,
|
|
148
|
+
Ntilde: 209,
|
|
149
|
+
Oacute: 211,
|
|
150
|
+
Ocirc: 212,
|
|
151
|
+
Ograve: 210,
|
|
152
|
+
Oslash: 216,
|
|
153
|
+
Otilde: 213,
|
|
154
|
+
Ouml: 214,
|
|
155
|
+
THORN: 222,
|
|
156
|
+
Uacute: 218,
|
|
157
|
+
Ucirc: 219,
|
|
158
|
+
Ugrave: 217,
|
|
159
|
+
Uuml: 220,
|
|
160
|
+
Yacute: 221,
|
|
161
|
+
aacute: 225,
|
|
162
|
+
acirc: 226,
|
|
163
|
+
aelig: 230,
|
|
164
|
+
agrave: 224,
|
|
165
|
+
aring: 229,
|
|
166
|
+
atilde: 227,
|
|
167
|
+
auml: 228,
|
|
168
|
+
ccedil: 231,
|
|
169
|
+
eacute: 233,
|
|
170
|
+
ecirc: 234,
|
|
171
|
+
egrave: 232,
|
|
172
|
+
eth: 240,
|
|
173
|
+
euml: 235,
|
|
174
|
+
iacute: 237,
|
|
175
|
+
icirc: 238,
|
|
176
|
+
igrave: 236,
|
|
177
|
+
iuml: 239,
|
|
178
|
+
ntilde: 241,
|
|
179
|
+
oacute: 243,
|
|
180
|
+
ocirc: 244,
|
|
181
|
+
ograve: 242,
|
|
182
|
+
oslash: 248,
|
|
183
|
+
otilde: 245,
|
|
184
|
+
ouml: 246,
|
|
185
|
+
szlig: 223,
|
|
186
|
+
thorn: 254,
|
|
187
|
+
uacute: 250,
|
|
188
|
+
ucirc: 251,
|
|
189
|
+
ugrave: 249,
|
|
190
|
+
uuml: 252,
|
|
191
|
+
yacute: 253,
|
|
192
|
+
yuml: 255,
|
|
193
|
+
copy: 169,
|
|
194
|
+
reg: 174,
|
|
195
|
+
nbsp: 160,
|
|
196
|
+
iexcl: 161,
|
|
197
|
+
cent: 162,
|
|
198
|
+
pound: 163,
|
|
199
|
+
curren: 164,
|
|
200
|
+
yen: 165,
|
|
201
|
+
brvbar: 166,
|
|
202
|
+
sect: 167,
|
|
203
|
+
uml: 168,
|
|
204
|
+
ordf: 170,
|
|
205
|
+
laquo: 171,
|
|
206
|
+
not: 172,
|
|
207
|
+
shy: 173,
|
|
208
|
+
macr: 175,
|
|
209
|
+
deg: 176,
|
|
210
|
+
plusmn: 177,
|
|
211
|
+
sup1: 185,
|
|
212
|
+
sup2: 178,
|
|
213
|
+
sup3: 179,
|
|
214
|
+
acute: 180,
|
|
215
|
+
micro: 181,
|
|
216
|
+
para: 182,
|
|
217
|
+
middot: 183,
|
|
218
|
+
cedil: 184,
|
|
219
|
+
ordm: 186,
|
|
220
|
+
raquo: 187,
|
|
221
|
+
frac14: 188,
|
|
222
|
+
frac12: 189,
|
|
223
|
+
frac34: 190,
|
|
224
|
+
iquest: 191,
|
|
225
|
+
times: 215,
|
|
226
|
+
divide: 247,
|
|
227
|
+
OElig: 338,
|
|
228
|
+
oelig: 339,
|
|
229
|
+
Scaron: 352,
|
|
230
|
+
scaron: 353,
|
|
231
|
+
Yuml: 376,
|
|
232
|
+
fnof: 402,
|
|
233
|
+
circ: 710,
|
|
234
|
+
tilde: 732,
|
|
235
|
+
Alpha: 913,
|
|
236
|
+
Beta: 914,
|
|
237
|
+
Gamma: 915,
|
|
238
|
+
Delta: 916,
|
|
239
|
+
Epsilon: 917,
|
|
240
|
+
Zeta: 918,
|
|
241
|
+
Eta: 919,
|
|
242
|
+
Theta: 920,
|
|
243
|
+
Iota: 921,
|
|
244
|
+
Kappa: 922,
|
|
245
|
+
Lambda: 923,
|
|
246
|
+
Mu: 924,
|
|
247
|
+
Nu: 925,
|
|
248
|
+
Xi: 926,
|
|
249
|
+
Omicron: 927,
|
|
250
|
+
Pi: 928,
|
|
251
|
+
Rho: 929,
|
|
252
|
+
Sigma: 931,
|
|
253
|
+
Tau: 932,
|
|
254
|
+
Upsilon: 933,
|
|
255
|
+
Phi: 934,
|
|
256
|
+
Chi: 935,
|
|
257
|
+
Psi: 936,
|
|
258
|
+
Omega: 937,
|
|
259
|
+
alpha: 945,
|
|
260
|
+
beta: 946,
|
|
261
|
+
gamma: 947,
|
|
262
|
+
delta: 948,
|
|
263
|
+
epsilon: 949,
|
|
264
|
+
zeta: 950,
|
|
265
|
+
eta: 951,
|
|
266
|
+
theta: 952,
|
|
267
|
+
iota: 953,
|
|
268
|
+
kappa: 954,
|
|
269
|
+
lambda: 955,
|
|
270
|
+
mu: 956,
|
|
271
|
+
nu: 957,
|
|
272
|
+
xi: 958,
|
|
273
|
+
omicron: 959,
|
|
274
|
+
pi: 960,
|
|
275
|
+
rho: 961,
|
|
276
|
+
sigmaf: 962,
|
|
277
|
+
sigma: 963,
|
|
278
|
+
tau: 964,
|
|
279
|
+
upsilon: 965,
|
|
280
|
+
phi: 966,
|
|
281
|
+
chi: 967,
|
|
282
|
+
psi: 968,
|
|
283
|
+
omega: 969,
|
|
284
|
+
thetasym: 977,
|
|
285
|
+
upsih: 978,
|
|
286
|
+
piv: 982,
|
|
287
|
+
ensp: 8194,
|
|
288
|
+
emsp: 8195,
|
|
289
|
+
thinsp: 8201,
|
|
290
|
+
zwnj: 8204,
|
|
291
|
+
zwj: 8205,
|
|
292
|
+
lrm: 8206,
|
|
293
|
+
rlm: 8207,
|
|
294
|
+
ndash: 8211,
|
|
295
|
+
mdash: 8212,
|
|
296
|
+
lsquo: 8216,
|
|
297
|
+
rsquo: 8217,
|
|
298
|
+
sbquo: 8218,
|
|
299
|
+
ldquo: 8220,
|
|
300
|
+
rdquo: 8221,
|
|
301
|
+
bdquo: 8222,
|
|
302
|
+
dagger: 8224,
|
|
303
|
+
Dagger: 8225,
|
|
304
|
+
bull: 8226,
|
|
305
|
+
hellip: 8230,
|
|
306
|
+
permil: 8240,
|
|
307
|
+
prime: 8242,
|
|
308
|
+
Prime: 8243,
|
|
309
|
+
lsaquo: 8249,
|
|
310
|
+
rsaquo: 8250,
|
|
311
|
+
oline: 8254,
|
|
312
|
+
frasl: 8260,
|
|
313
|
+
euro: 8364,
|
|
314
|
+
image: 8465,
|
|
315
|
+
weierp: 8472,
|
|
316
|
+
real: 8476,
|
|
317
|
+
trade: 8482,
|
|
318
|
+
alefsym: 8501,
|
|
319
|
+
larr: 8592,
|
|
320
|
+
uarr: 8593,
|
|
321
|
+
rarr: 8594,
|
|
322
|
+
darr: 8595,
|
|
323
|
+
harr: 8596,
|
|
324
|
+
crarr: 8629,
|
|
325
|
+
lArr: 8656,
|
|
326
|
+
uArr: 8657,
|
|
327
|
+
rArr: 8658,
|
|
328
|
+
dArr: 8659,
|
|
329
|
+
hArr: 8660,
|
|
330
|
+
forall: 8704,
|
|
331
|
+
part: 8706,
|
|
332
|
+
exist: 8707,
|
|
333
|
+
empty: 8709,
|
|
334
|
+
nabla: 8711,
|
|
335
|
+
isin: 8712,
|
|
336
|
+
notin: 8713,
|
|
337
|
+
ni: 8715,
|
|
338
|
+
prod: 8719,
|
|
339
|
+
sum: 8721,
|
|
340
|
+
minus: 8722,
|
|
341
|
+
lowast: 8727,
|
|
342
|
+
radic: 8730,
|
|
343
|
+
prop: 8733,
|
|
344
|
+
infin: 8734,
|
|
345
|
+
ang: 8736,
|
|
346
|
+
and: 8743,
|
|
347
|
+
or: 8744,
|
|
348
|
+
cap: 8745,
|
|
349
|
+
cup: 8746,
|
|
350
|
+
int: 8747,
|
|
351
|
+
there4: 8756,
|
|
352
|
+
sim: 8764,
|
|
353
|
+
cong: 8773,
|
|
354
|
+
asymp: 8776,
|
|
355
|
+
ne: 8800,
|
|
356
|
+
equiv: 8801,
|
|
357
|
+
le: 8804,
|
|
358
|
+
ge: 8805,
|
|
359
|
+
sub: 8834,
|
|
360
|
+
sup: 8835,
|
|
361
|
+
nsub: 8836,
|
|
362
|
+
sube: 8838,
|
|
363
|
+
supe: 8839,
|
|
364
|
+
oplus: 8853,
|
|
365
|
+
otimes: 8855,
|
|
366
|
+
perp: 8869,
|
|
367
|
+
sdot: 8901,
|
|
368
|
+
lceil: 8968,
|
|
369
|
+
rceil: 8969,
|
|
370
|
+
lfloor: 8970,
|
|
371
|
+
rfloor: 8971,
|
|
372
|
+
lang: 9001,
|
|
373
|
+
rang: 9002,
|
|
374
|
+
loz: 9674,
|
|
375
|
+
spades: 9824,
|
|
376
|
+
clubs: 9827,
|
|
377
|
+
hearts: 9829,
|
|
378
|
+
diams: 9830
|
|
379
|
+
};
|
|
380
|
+
Object.keys(ENTITIES).forEach((key) => {
|
|
381
|
+
const e = ENTITIES[key];
|
|
382
|
+
ENTITIES[key] = typeof e === "number" ? String.fromCharCode(e) : e;
|
|
383
|
+
});
|
|
384
|
+
SAX = class {
|
|
385
|
+
constructor() {
|
|
386
|
+
this.EVENTS = EVENTS;
|
|
387
|
+
this.ENTITIES = {
|
|
388
|
+
...ENTITIES
|
|
389
|
+
};
|
|
390
|
+
this.XML_ENTITIES = {
|
|
391
|
+
amp: "&",
|
|
392
|
+
gt: ">",
|
|
393
|
+
lt: "<",
|
|
394
|
+
quot: '"',
|
|
395
|
+
apos: "'"
|
|
396
|
+
};
|
|
397
|
+
this.S = 0;
|
|
398
|
+
this.trackPosition = false;
|
|
399
|
+
this.column = 0;
|
|
400
|
+
this.line = 0;
|
|
401
|
+
this.c = "";
|
|
402
|
+
this.q = "";
|
|
403
|
+
this.closed = false;
|
|
404
|
+
this.tags = [];
|
|
405
|
+
this.looseCase = "";
|
|
406
|
+
this.closedRoot = false;
|
|
407
|
+
this.sawRoot = false;
|
|
408
|
+
this.strict = false;
|
|
409
|
+
this.noscript = false;
|
|
410
|
+
this.attribList = [];
|
|
411
|
+
this.position = 0;
|
|
412
|
+
this.STATE = {
|
|
413
|
+
BEGIN: this.S++,
|
|
414
|
+
BEGIN_WHITESPACE: this.S++,
|
|
415
|
+
TEXT: this.S++,
|
|
416
|
+
TEXT_ENTITY: this.S++,
|
|
417
|
+
OPEN_WAKA: this.S++,
|
|
418
|
+
SGML_DECL: this.S++,
|
|
419
|
+
SGML_DECL_QUOTED: this.S++,
|
|
420
|
+
DOCTYPE: this.S++,
|
|
421
|
+
DOCTYPE_QUOTED: this.S++,
|
|
422
|
+
DOCTYPE_DTD: this.S++,
|
|
423
|
+
DOCTYPE_DTD_QUOTED: this.S++,
|
|
424
|
+
COMMENT_STARTING: this.S++,
|
|
425
|
+
COMMENT: this.S++,
|
|
426
|
+
COMMENT_ENDING: this.S++,
|
|
427
|
+
COMMENT_ENDED: this.S++,
|
|
428
|
+
CDATA: this.S++,
|
|
429
|
+
CDATA_ENDING: this.S++,
|
|
430
|
+
CDATA_ENDING_2: this.S++,
|
|
431
|
+
PROC_INST: this.S++,
|
|
432
|
+
PROC_INST_BODY: this.S++,
|
|
433
|
+
PROC_INST_ENDING: this.S++,
|
|
434
|
+
OPEN_TAG: this.S++,
|
|
435
|
+
OPEN_TAG_SLASH: this.S++,
|
|
436
|
+
ATTRIB: this.S++,
|
|
437
|
+
ATTRIB_NAME: this.S++,
|
|
438
|
+
ATTRIB_NAME_SAW_WHITE: this.S++,
|
|
439
|
+
ATTRIB_VALUE: this.S++,
|
|
440
|
+
ATTRIB_VALUE_QUOTED: this.S++,
|
|
441
|
+
ATTRIB_VALUE_CLOSED: this.S++,
|
|
442
|
+
ATTRIB_VALUE_UNQUOTED: this.S++,
|
|
443
|
+
ATTRIB_VALUE_ENTITY_Q: this.S++,
|
|
444
|
+
ATTRIB_VALUE_ENTITY_U: this.S++,
|
|
445
|
+
CLOSE_TAG: this.S++,
|
|
446
|
+
CLOSE_TAG_SAW_WHITE: this.S++,
|
|
447
|
+
SCRIPT: this.S++,
|
|
448
|
+
SCRIPT_ENDING: this.S++
|
|
449
|
+
};
|
|
450
|
+
this.BUFFERS = BUFFERS;
|
|
451
|
+
this.CDATA = "[CDATA[";
|
|
452
|
+
this.DOCTYPE = "DOCTYPE";
|
|
453
|
+
this.XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
|
|
454
|
+
this.XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
|
|
455
|
+
this.rootNS = {
|
|
456
|
+
xml: this.XML_NAMESPACE,
|
|
457
|
+
xmlns: this.XMLNS_NAMESPACE
|
|
458
|
+
};
|
|
459
|
+
this.textNode = "";
|
|
460
|
+
this.entity = "";
|
|
461
|
+
this.cdata = "";
|
|
462
|
+
this.script = "";
|
|
463
|
+
this.startTagPosition = 0;
|
|
464
|
+
this.S = 0;
|
|
465
|
+
for (const s in this.STATE) {
|
|
466
|
+
if (this.STATE.hasOwnProperty(s)) {
|
|
467
|
+
this.STATE[this.STATE[s]] = s;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
this.S = this.STATE;
|
|
471
|
+
}
|
|
472
|
+
static charAt(chunk, i) {
|
|
473
|
+
let result = "";
|
|
474
|
+
if (i < chunk.length) {
|
|
475
|
+
result = chunk.charAt(i);
|
|
476
|
+
}
|
|
477
|
+
return result;
|
|
478
|
+
}
|
|
479
|
+
static isWhitespace(c) {
|
|
480
|
+
return c === " " || c === "\n" || c === "\r" || c === " ";
|
|
481
|
+
}
|
|
482
|
+
static isQuote(c) {
|
|
483
|
+
return c === '"' || c === "'";
|
|
484
|
+
}
|
|
485
|
+
static isAttribEnd(c) {
|
|
486
|
+
return c === ">" || SAX.isWhitespace(c);
|
|
487
|
+
}
|
|
488
|
+
static isMatch(regex, c) {
|
|
489
|
+
return regex.test(c);
|
|
490
|
+
}
|
|
491
|
+
static notMatch(regex, c) {
|
|
492
|
+
return !SAX.isMatch(regex, c);
|
|
493
|
+
}
|
|
494
|
+
static qname(name, attribute) {
|
|
495
|
+
const i = name.indexOf(":");
|
|
496
|
+
const qualName = i < 0 ? ["", name] : name.split(":");
|
|
497
|
+
let prefix = qualName[0];
|
|
498
|
+
let local = qualName[1];
|
|
499
|
+
if (attribute && name === "xmlns") {
|
|
500
|
+
prefix = "xmlns";
|
|
501
|
+
local = "";
|
|
502
|
+
}
|
|
503
|
+
return { prefix, local };
|
|
504
|
+
}
|
|
505
|
+
write(chunk) {
|
|
506
|
+
if (this.error) {
|
|
507
|
+
throw this.error;
|
|
508
|
+
}
|
|
509
|
+
if (this.closed) {
|
|
510
|
+
return this.errorFunction("Cannot write after close. Assign an onready handler.");
|
|
511
|
+
}
|
|
512
|
+
if (chunk === null) {
|
|
513
|
+
return this.end();
|
|
514
|
+
}
|
|
515
|
+
if (typeof chunk === "object") {
|
|
516
|
+
chunk = chunk.toString();
|
|
517
|
+
}
|
|
518
|
+
let i = 0;
|
|
519
|
+
let c;
|
|
520
|
+
while (true) {
|
|
521
|
+
c = SAX.charAt(chunk, i++);
|
|
522
|
+
this.c = c;
|
|
523
|
+
if (!c) {
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
if (this.trackPosition) {
|
|
527
|
+
this.position++;
|
|
528
|
+
if (c === "\n") {
|
|
529
|
+
this.line++;
|
|
530
|
+
this.column = 0;
|
|
531
|
+
} else {
|
|
532
|
+
this.column++;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
switch (this.state) {
|
|
536
|
+
case this.S.BEGIN:
|
|
537
|
+
this.state = this.S.BEGIN_WHITESPACE;
|
|
538
|
+
if (c === "\uFEFF") {
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
this.beginWhiteSpace(c);
|
|
542
|
+
continue;
|
|
543
|
+
case this.S.BEGIN_WHITESPACE:
|
|
544
|
+
this.beginWhiteSpace(c);
|
|
545
|
+
continue;
|
|
546
|
+
case this.S.TEXT:
|
|
547
|
+
if (this.sawRoot && !this.closedRoot) {
|
|
548
|
+
const starti = i - 1;
|
|
549
|
+
while (c && c !== "<" && c !== "&") {
|
|
550
|
+
c = SAX.charAt(chunk, i++);
|
|
551
|
+
if (c && this.trackPosition) {
|
|
552
|
+
this.position++;
|
|
553
|
+
if (c === "\n") {
|
|
554
|
+
this.line++;
|
|
555
|
+
this.column = 0;
|
|
556
|
+
} else {
|
|
557
|
+
this.column++;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
this.textNode += chunk.substring(starti, i - 1);
|
|
562
|
+
}
|
|
563
|
+
if (c === "<" && !(this.sawRoot && this.closedRoot && !this.strict)) {
|
|
564
|
+
this.state = this.S.OPEN_WAKA;
|
|
565
|
+
this.startTagPosition = this.position;
|
|
566
|
+
} else {
|
|
567
|
+
if (!SAX.isWhitespace(c) && (!this.sawRoot || this.closedRoot)) {
|
|
568
|
+
this.strictFail("Text data outside of root node.");
|
|
569
|
+
}
|
|
570
|
+
if (c === "&") {
|
|
571
|
+
this.state = this.S.TEXT_ENTITY;
|
|
572
|
+
} else {
|
|
573
|
+
this.textNode += c;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
continue;
|
|
577
|
+
case this.S.SCRIPT:
|
|
578
|
+
if (c === "<") {
|
|
579
|
+
this.state = this.S.SCRIPT_ENDING;
|
|
580
|
+
} else {
|
|
581
|
+
this.script += c;
|
|
582
|
+
}
|
|
583
|
+
continue;
|
|
584
|
+
case this.S.SCRIPT_ENDING:
|
|
585
|
+
if (c === "/") {
|
|
586
|
+
this.state = this.S.CLOSE_TAG;
|
|
587
|
+
} else {
|
|
588
|
+
this.script += `<${c}`;
|
|
589
|
+
this.state = this.S.SCRIPT;
|
|
590
|
+
}
|
|
591
|
+
continue;
|
|
592
|
+
case this.S.OPEN_WAKA:
|
|
593
|
+
if (c === "!") {
|
|
594
|
+
this.state = this.S.SGML_DECL;
|
|
595
|
+
this.sgmlDecl = "";
|
|
596
|
+
} else if (SAX.isWhitespace(c)) {
|
|
597
|
+
} else if (SAX.isMatch(nameStart, c)) {
|
|
598
|
+
this.state = this.S.OPEN_TAG;
|
|
599
|
+
this.tagName = c;
|
|
600
|
+
} else if (c === "/") {
|
|
601
|
+
this.state = this.S.CLOSE_TAG;
|
|
602
|
+
this.tagName = "";
|
|
603
|
+
} else if (c === "?") {
|
|
604
|
+
this.state = this.S.PROC_INST;
|
|
605
|
+
this.procInstName = this.procInstBody = "";
|
|
606
|
+
} else {
|
|
607
|
+
this.strictFail("Unencoded <");
|
|
608
|
+
if (this.startTagPosition + 1 < this.position) {
|
|
609
|
+
const pad = this.position - this.startTagPosition;
|
|
610
|
+
c = new Array(pad).join(" ") + c;
|
|
611
|
+
}
|
|
612
|
+
this.textNode += `<${c}`;
|
|
613
|
+
this.state = this.S.TEXT;
|
|
614
|
+
}
|
|
615
|
+
continue;
|
|
616
|
+
case this.S.SGML_DECL:
|
|
617
|
+
if ((this.sgmlDecl + c).toUpperCase() === this.CDATA) {
|
|
618
|
+
this.emitNode("onopencdata");
|
|
619
|
+
this.state = this.S.CDATA;
|
|
620
|
+
this.sgmlDecl = "";
|
|
621
|
+
this.cdata = "";
|
|
622
|
+
} else if (this.sgmlDecl + c === "--") {
|
|
623
|
+
this.state = this.S.COMMENT;
|
|
624
|
+
this.comment = "";
|
|
625
|
+
this.sgmlDecl = "";
|
|
626
|
+
} else if ((this.sgmlDecl + c).toUpperCase() === this.DOCTYPE) {
|
|
627
|
+
this.state = this.S.DOCTYPE;
|
|
628
|
+
if (this.doctype || this.sawRoot) {
|
|
629
|
+
this.strictFail("Inappropriately located doctype declaration");
|
|
630
|
+
}
|
|
631
|
+
this.doctype = "";
|
|
632
|
+
this.sgmlDecl = "";
|
|
633
|
+
} else if (c === ">") {
|
|
634
|
+
this.emitNode("onsgmldeclaration", this.sgmlDecl);
|
|
635
|
+
this.sgmlDecl = "";
|
|
636
|
+
this.state = this.S.TEXT;
|
|
637
|
+
} else if (SAX.isQuote(c)) {
|
|
638
|
+
this.state = this.S.SGML_DECL_QUOTED;
|
|
639
|
+
this.sgmlDecl += c;
|
|
640
|
+
} else {
|
|
641
|
+
this.sgmlDecl += c;
|
|
642
|
+
}
|
|
643
|
+
continue;
|
|
644
|
+
case this.S.SGML_DECL_QUOTED:
|
|
645
|
+
if (c === this.q) {
|
|
646
|
+
this.state = this.S.SGML_DECL;
|
|
647
|
+
this.q = "";
|
|
648
|
+
}
|
|
649
|
+
this.sgmlDecl += c;
|
|
650
|
+
continue;
|
|
651
|
+
case this.S.DOCTYPE:
|
|
652
|
+
if (c === ">") {
|
|
653
|
+
this.state = this.S.TEXT;
|
|
654
|
+
this.emitNode("ondoctype", this.doctype);
|
|
655
|
+
this.doctype = true;
|
|
656
|
+
} else {
|
|
657
|
+
this.doctype += c;
|
|
658
|
+
if (c === "[") {
|
|
659
|
+
this.state = this.S.DOCTYPE_DTD;
|
|
660
|
+
} else if (SAX.isQuote(c)) {
|
|
661
|
+
this.state = this.S.DOCTYPE_QUOTED;
|
|
662
|
+
this.q = c;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
continue;
|
|
666
|
+
case this.S.DOCTYPE_QUOTED:
|
|
667
|
+
this.doctype += c;
|
|
668
|
+
if (c === this.q) {
|
|
669
|
+
this.q = "";
|
|
670
|
+
this.state = this.S.DOCTYPE;
|
|
671
|
+
}
|
|
672
|
+
continue;
|
|
673
|
+
case this.S.DOCTYPE_DTD:
|
|
674
|
+
this.doctype += c;
|
|
675
|
+
if (c === "]") {
|
|
676
|
+
this.state = this.S.DOCTYPE;
|
|
677
|
+
} else if (SAX.isQuote(c)) {
|
|
678
|
+
this.state = this.S.DOCTYPE_DTD_QUOTED;
|
|
679
|
+
this.q = c;
|
|
680
|
+
}
|
|
681
|
+
continue;
|
|
682
|
+
case this.S.DOCTYPE_DTD_QUOTED:
|
|
683
|
+
this.doctype += c;
|
|
684
|
+
if (c === this.q) {
|
|
685
|
+
this.state = this.S.DOCTYPE_DTD;
|
|
686
|
+
this.q = "";
|
|
687
|
+
}
|
|
688
|
+
continue;
|
|
689
|
+
case this.S.COMMENT:
|
|
690
|
+
if (c === "-") {
|
|
691
|
+
this.state = this.S.COMMENT_ENDING;
|
|
692
|
+
} else {
|
|
693
|
+
this.comment += c;
|
|
694
|
+
}
|
|
695
|
+
continue;
|
|
696
|
+
case this.S.COMMENT_ENDING:
|
|
697
|
+
if (c === "-") {
|
|
698
|
+
this.state = this.S.COMMENT_ENDED;
|
|
699
|
+
this.comment = this.textApplyOptions(this.comment);
|
|
700
|
+
if (this.comment) {
|
|
701
|
+
this.emitNode("oncomment", this.comment);
|
|
702
|
+
}
|
|
703
|
+
this.comment = "";
|
|
704
|
+
} else {
|
|
705
|
+
this.comment += `-${c}`;
|
|
706
|
+
this.state = this.S.COMMENT;
|
|
707
|
+
}
|
|
708
|
+
continue;
|
|
709
|
+
case this.S.COMMENT_ENDED:
|
|
710
|
+
if (c !== ">") {
|
|
711
|
+
this.strictFail("Malformed comment");
|
|
712
|
+
this.comment += `--${c}`;
|
|
713
|
+
this.state = this.S.COMMENT;
|
|
714
|
+
} else {
|
|
715
|
+
this.state = this.S.TEXT;
|
|
716
|
+
}
|
|
717
|
+
continue;
|
|
718
|
+
case this.S.CDATA:
|
|
719
|
+
if (c === "]") {
|
|
720
|
+
this.state = this.S.CDATA_ENDING;
|
|
721
|
+
} else {
|
|
722
|
+
this.cdata += c;
|
|
723
|
+
}
|
|
724
|
+
continue;
|
|
725
|
+
case this.S.CDATA_ENDING:
|
|
726
|
+
if (c === "]") {
|
|
727
|
+
this.state = this.S.CDATA_ENDING_2;
|
|
728
|
+
} else {
|
|
729
|
+
this.cdata += `]${c}`;
|
|
730
|
+
this.state = this.S.CDATA;
|
|
731
|
+
}
|
|
732
|
+
continue;
|
|
733
|
+
case this.S.CDATA_ENDING_2:
|
|
734
|
+
if (c === ">") {
|
|
735
|
+
if (this.cdata) {
|
|
736
|
+
this.emitNode("oncdata", this.cdata);
|
|
737
|
+
}
|
|
738
|
+
this.emitNode("onclosecdata");
|
|
739
|
+
this.cdata = "";
|
|
740
|
+
this.state = this.S.TEXT;
|
|
741
|
+
} else if (c === "]") {
|
|
742
|
+
this.cdata += "]";
|
|
743
|
+
} else {
|
|
744
|
+
this.cdata += `]]${c}`;
|
|
745
|
+
this.state = this.S.CDATA;
|
|
746
|
+
}
|
|
747
|
+
continue;
|
|
748
|
+
case this.S.PROC_INST:
|
|
749
|
+
if (c === "?") {
|
|
750
|
+
this.state = this.S.PROC_INST_ENDING;
|
|
751
|
+
} else if (SAX.isWhitespace(c)) {
|
|
752
|
+
this.state = this.S.PROC_INST_BODY;
|
|
753
|
+
} else {
|
|
754
|
+
this.procInstName += c;
|
|
755
|
+
}
|
|
756
|
+
continue;
|
|
757
|
+
case this.S.PROC_INST_BODY:
|
|
758
|
+
if (!this.procInstBody && SAX.isWhitespace(c)) {
|
|
759
|
+
continue;
|
|
760
|
+
} else if (c === "?") {
|
|
761
|
+
this.state = this.S.PROC_INST_ENDING;
|
|
762
|
+
} else {
|
|
763
|
+
this.procInstBody += c;
|
|
764
|
+
}
|
|
765
|
+
continue;
|
|
766
|
+
case this.S.PROC_INST_ENDING:
|
|
767
|
+
if (c === ">") {
|
|
768
|
+
this.emitNode("onprocessinginstruction", {
|
|
769
|
+
name: this.procInstName,
|
|
770
|
+
body: this.procInstBody
|
|
771
|
+
});
|
|
772
|
+
this.procInstName = this.procInstBody = "";
|
|
773
|
+
this.state = this.S.TEXT;
|
|
774
|
+
} else {
|
|
775
|
+
this.procInstBody += `?${c}`;
|
|
776
|
+
this.state = this.S.PROC_INST_BODY;
|
|
777
|
+
}
|
|
778
|
+
continue;
|
|
779
|
+
case this.S.OPEN_TAG:
|
|
780
|
+
if (SAX.isMatch(nameBody, c)) {
|
|
781
|
+
this.tagName += c;
|
|
782
|
+
} else {
|
|
783
|
+
this.newTag();
|
|
784
|
+
if (c === ">") {
|
|
785
|
+
this.openTag();
|
|
786
|
+
} else if (c === "/") {
|
|
787
|
+
this.state = this.S.OPEN_TAG_SLASH;
|
|
788
|
+
} else {
|
|
789
|
+
if (!SAX.isWhitespace(c)) {
|
|
790
|
+
this.strictFail("Invalid character in tag name");
|
|
791
|
+
}
|
|
792
|
+
this.state = this.S.ATTRIB;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
continue;
|
|
796
|
+
case this.S.OPEN_TAG_SLASH:
|
|
797
|
+
if (c === ">") {
|
|
798
|
+
this.openTag(true);
|
|
799
|
+
this.closeTag();
|
|
800
|
+
} else {
|
|
801
|
+
this.strictFail("Forward-slash in opening tag not followed by >");
|
|
802
|
+
this.state = this.S.ATTRIB;
|
|
803
|
+
}
|
|
804
|
+
continue;
|
|
805
|
+
case this.S.ATTRIB:
|
|
806
|
+
if (SAX.isWhitespace(c)) {
|
|
807
|
+
continue;
|
|
808
|
+
} else if (c === ">") {
|
|
809
|
+
this.openTag();
|
|
810
|
+
} else if (c === "/") {
|
|
811
|
+
this.state = this.S.OPEN_TAG_SLASH;
|
|
812
|
+
} else if (SAX.isMatch(nameStart, c)) {
|
|
813
|
+
this.attribName = c;
|
|
814
|
+
this.attribValue = "";
|
|
815
|
+
this.state = this.S.ATTRIB_NAME;
|
|
816
|
+
} else {
|
|
817
|
+
this.strictFail("Invalid attribute name");
|
|
818
|
+
}
|
|
819
|
+
continue;
|
|
820
|
+
case this.S.ATTRIB_NAME:
|
|
821
|
+
if (c === "=") {
|
|
822
|
+
this.state = this.S.ATTRIB_VALUE;
|
|
823
|
+
} else if (c === ">") {
|
|
824
|
+
this.strictFail("Attribute without value");
|
|
825
|
+
this.attribValue = this.attribName;
|
|
826
|
+
this.attrib();
|
|
827
|
+
this.openTag();
|
|
828
|
+
} else if (SAX.isWhitespace(c)) {
|
|
829
|
+
this.state = this.S.ATTRIB_NAME_SAW_WHITE;
|
|
830
|
+
} else if (SAX.isMatch(nameBody, c)) {
|
|
831
|
+
this.attribName += c;
|
|
832
|
+
} else {
|
|
833
|
+
this.strictFail("Invalid attribute name");
|
|
834
|
+
}
|
|
835
|
+
continue;
|
|
836
|
+
case this.S.ATTRIB_NAME_SAW_WHITE:
|
|
837
|
+
if (c === "=") {
|
|
838
|
+
this.state = this.S.ATTRIB_VALUE;
|
|
839
|
+
} else if (SAX.isWhitespace(c)) {
|
|
840
|
+
continue;
|
|
841
|
+
} else {
|
|
842
|
+
this.strictFail("Attribute without value");
|
|
843
|
+
this.tag.attributes[this.attribName] = "";
|
|
844
|
+
this.attribValue = "";
|
|
845
|
+
this.emitNode("onattribute", {
|
|
846
|
+
name: this.attribName,
|
|
847
|
+
value: ""
|
|
848
|
+
});
|
|
849
|
+
this.attribName = "";
|
|
850
|
+
if (c === ">") {
|
|
851
|
+
this.openTag();
|
|
852
|
+
} else if (SAX.isMatch(nameStart, c)) {
|
|
853
|
+
this.attribName = c;
|
|
854
|
+
this.state = this.S.ATTRIB_NAME;
|
|
855
|
+
} else {
|
|
856
|
+
this.strictFail("Invalid attribute name");
|
|
857
|
+
this.state = this.S.ATTRIB;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
continue;
|
|
861
|
+
case this.S.ATTRIB_VALUE:
|
|
862
|
+
if (SAX.isWhitespace(c)) {
|
|
863
|
+
continue;
|
|
864
|
+
} else if (SAX.isQuote(c)) {
|
|
865
|
+
this.q = c;
|
|
866
|
+
this.state = this.S.ATTRIB_VALUE_QUOTED;
|
|
867
|
+
} else {
|
|
868
|
+
this.strictFail("Unquoted attribute value");
|
|
869
|
+
this.state = this.S.ATTRIB_VALUE_UNQUOTED;
|
|
870
|
+
this.attribValue = c;
|
|
871
|
+
}
|
|
872
|
+
continue;
|
|
873
|
+
case this.S.ATTRIB_VALUE_QUOTED:
|
|
874
|
+
if (c !== this.q) {
|
|
875
|
+
if (c === "&") {
|
|
876
|
+
this.state = this.S.ATTRIB_VALUE_ENTITY_Q;
|
|
877
|
+
} else {
|
|
878
|
+
this.attribValue += c;
|
|
879
|
+
}
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
this.attrib();
|
|
883
|
+
this.q = "";
|
|
884
|
+
this.state = this.S.ATTRIB_VALUE_CLOSED;
|
|
885
|
+
continue;
|
|
886
|
+
case this.S.ATTRIB_VALUE_CLOSED:
|
|
887
|
+
if (SAX.isWhitespace(c)) {
|
|
888
|
+
this.state = this.S.ATTRIB;
|
|
889
|
+
} else if (c === ">") {
|
|
890
|
+
this.openTag();
|
|
891
|
+
} else if (c === "/") {
|
|
892
|
+
this.state = this.S.OPEN_TAG_SLASH;
|
|
893
|
+
} else if (SAX.isMatch(nameStart, c)) {
|
|
894
|
+
this.strictFail("No whitespace between attributes");
|
|
895
|
+
this.attribName = c;
|
|
896
|
+
this.attribValue = "";
|
|
897
|
+
this.state = this.S.ATTRIB_NAME;
|
|
898
|
+
} else {
|
|
899
|
+
this.strictFail("Invalid attribute name");
|
|
900
|
+
}
|
|
901
|
+
continue;
|
|
902
|
+
case this.S.ATTRIB_VALUE_UNQUOTED:
|
|
903
|
+
if (!SAX.isAttribEnd(c)) {
|
|
904
|
+
if (c === "&") {
|
|
905
|
+
this.state = this.S.ATTRIB_VALUE_ENTITY_U;
|
|
906
|
+
} else {
|
|
907
|
+
this.attribValue += c;
|
|
908
|
+
}
|
|
909
|
+
continue;
|
|
910
|
+
}
|
|
911
|
+
this.attrib();
|
|
912
|
+
if (c === ">") {
|
|
913
|
+
this.openTag();
|
|
914
|
+
} else {
|
|
915
|
+
this.state = this.S.ATTRIB;
|
|
916
|
+
}
|
|
917
|
+
continue;
|
|
918
|
+
case this.S.CLOSE_TAG:
|
|
919
|
+
if (!this.tagName) {
|
|
920
|
+
if (SAX.isWhitespace(c)) {
|
|
921
|
+
continue;
|
|
922
|
+
} else if (SAX.notMatch(nameStart, c)) {
|
|
923
|
+
if (this.script) {
|
|
924
|
+
this.script += `</${c}`;
|
|
925
|
+
this.state = this.S.SCRIPT;
|
|
926
|
+
} else {
|
|
927
|
+
this.strictFail("Invalid tagname in closing tag.");
|
|
928
|
+
}
|
|
929
|
+
} else {
|
|
930
|
+
this.tagName = c;
|
|
931
|
+
}
|
|
932
|
+
} else if (c === ">") {
|
|
933
|
+
this.closeTag();
|
|
934
|
+
} else if (SAX.isMatch(nameBody, c)) {
|
|
935
|
+
this.tagName += c;
|
|
936
|
+
} else if (this.script) {
|
|
937
|
+
this.script += `</${this.tagName}`;
|
|
938
|
+
this.tagName = "";
|
|
939
|
+
this.state = this.S.SCRIPT;
|
|
940
|
+
} else {
|
|
941
|
+
if (!SAX.isWhitespace(c)) {
|
|
942
|
+
this.strictFail("Invalid tagname in closing tag");
|
|
943
|
+
}
|
|
944
|
+
this.state = this.S.CLOSE_TAG_SAW_WHITE;
|
|
945
|
+
}
|
|
946
|
+
continue;
|
|
947
|
+
case this.S.CLOSE_TAG_SAW_WHITE:
|
|
948
|
+
if (SAX.isWhitespace(c)) {
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
if (c === ">") {
|
|
952
|
+
this.closeTag();
|
|
953
|
+
} else {
|
|
954
|
+
this.strictFail("Invalid characters in closing tag");
|
|
955
|
+
}
|
|
956
|
+
continue;
|
|
957
|
+
case this.S.TEXT_ENTITY:
|
|
958
|
+
case this.S.ATTRIB_VALUE_ENTITY_Q:
|
|
959
|
+
case this.S.ATTRIB_VALUE_ENTITY_U:
|
|
960
|
+
let returnState;
|
|
961
|
+
let buffer;
|
|
962
|
+
switch (this.state) {
|
|
963
|
+
case this.S.TEXT_ENTITY:
|
|
964
|
+
returnState = this.S.TEXT;
|
|
965
|
+
buffer = "textNode";
|
|
966
|
+
break;
|
|
967
|
+
case this.S.ATTRIB_VALUE_ENTITY_Q:
|
|
968
|
+
returnState = this.S.ATTRIB_VALUE_QUOTED;
|
|
969
|
+
buffer = "attribValue";
|
|
970
|
+
break;
|
|
971
|
+
case this.S.ATTRIB_VALUE_ENTITY_U:
|
|
972
|
+
returnState = this.S.ATTRIB_VALUE_UNQUOTED;
|
|
973
|
+
buffer = "attribValue";
|
|
974
|
+
break;
|
|
975
|
+
default:
|
|
976
|
+
throw new Error(`Unknown state: ${this.state}`);
|
|
977
|
+
}
|
|
978
|
+
if (c === ";") {
|
|
979
|
+
this[buffer] += this.parseEntity();
|
|
980
|
+
this.entity = "";
|
|
981
|
+
this.state = returnState;
|
|
982
|
+
} else if (SAX.isMatch(this.entity.length ? entityBody : entityStart, c)) {
|
|
983
|
+
this.entity += c;
|
|
984
|
+
} else {
|
|
985
|
+
this.strictFail("Invalid character in entity name");
|
|
986
|
+
this[buffer] += `&${this.entity}${c}`;
|
|
987
|
+
this.entity = "";
|
|
988
|
+
this.state = returnState;
|
|
989
|
+
}
|
|
990
|
+
continue;
|
|
991
|
+
default:
|
|
992
|
+
throw new Error(`Unknown state: ${this.state}`);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
if (this.position >= this.bufferCheckPosition) {
|
|
996
|
+
this.checkBufferLength();
|
|
997
|
+
}
|
|
998
|
+
return this;
|
|
999
|
+
}
|
|
1000
|
+
emit(event, data) {
|
|
1001
|
+
if (this.events.hasOwnProperty(event)) {
|
|
1002
|
+
const eventName = event.replace(/^on/, "");
|
|
1003
|
+
this.events[event](data, eventName, this);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
clearBuffers() {
|
|
1007
|
+
for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
|
|
1008
|
+
this[this[i]] = "";
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
flushBuffers() {
|
|
1012
|
+
this.closeText();
|
|
1013
|
+
if (this.cdata !== "") {
|
|
1014
|
+
this.emitNode("oncdata", this.cdata);
|
|
1015
|
+
this.cdata = "";
|
|
1016
|
+
}
|
|
1017
|
+
if (this.script !== "") {
|
|
1018
|
+
this.emitNode("onscript", this.script);
|
|
1019
|
+
this.script = "";
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
end() {
|
|
1023
|
+
if (this.sawRoot && !this.closedRoot)
|
|
1024
|
+
this.strictFail("Unclosed root tag");
|
|
1025
|
+
if (this.state !== this.S.BEGIN && this.state !== this.S.BEGIN_WHITESPACE && this.state !== this.S.TEXT) {
|
|
1026
|
+
this.errorFunction("Unexpected end");
|
|
1027
|
+
}
|
|
1028
|
+
this.closeText();
|
|
1029
|
+
this.c = "";
|
|
1030
|
+
this.closed = true;
|
|
1031
|
+
this.emit("onend");
|
|
1032
|
+
return new SAXParser(this.opt);
|
|
1033
|
+
}
|
|
1034
|
+
errorFunction(er) {
|
|
1035
|
+
this.closeText();
|
|
1036
|
+
if (this.trackPosition) {
|
|
1037
|
+
er += `
|
|
1038
|
+
Line: ${this.line}
|
|
1039
|
+
Column: ${this.column}
|
|
1040
|
+
Char: ${this.c}`;
|
|
1041
|
+
}
|
|
1042
|
+
const error = new Error(er);
|
|
1043
|
+
this.error = error;
|
|
1044
|
+
this.emit("onerror", error);
|
|
1045
|
+
return this;
|
|
1046
|
+
}
|
|
1047
|
+
attrib() {
|
|
1048
|
+
if (!this.strict) {
|
|
1049
|
+
this.attribName = this.attribName[this.looseCase]();
|
|
1050
|
+
}
|
|
1051
|
+
if (this.attribList.indexOf(this.attribName) !== -1 || this.tag.attributes.hasOwnProperty(this.attribName)) {
|
|
1052
|
+
this.attribName = this.attribValue = "";
|
|
1053
|
+
return;
|
|
1054
|
+
}
|
|
1055
|
+
if (this.opt.xmlns) {
|
|
1056
|
+
const qn = SAX.qname(this.attribName, true);
|
|
1057
|
+
const prefix = qn.prefix;
|
|
1058
|
+
const local = qn.local;
|
|
1059
|
+
if (prefix === "xmlns") {
|
|
1060
|
+
if (local === "xml" && this.attribValue !== this.XML_NAMESPACE) {
|
|
1061
|
+
this.strictFail(`xml: prefix must be bound to ${this.XML_NAMESPACE}
|
|
1062
|
+
Actual: ${this.attribValue}`);
|
|
1063
|
+
} else if (local === "xmlns" && this.attribValue !== this.XMLNS_NAMESPACE) {
|
|
1064
|
+
this.strictFail(`xmlns: prefix must be bound to ${this.XMLNS_NAMESPACE}
|
|
1065
|
+
Actual: ${this.attribValue}`);
|
|
1066
|
+
} else {
|
|
1067
|
+
const tag = this.tag;
|
|
1068
|
+
const parent = this.tags[this.tags.length - 1] || this;
|
|
1069
|
+
if (tag.ns === parent.ns) {
|
|
1070
|
+
tag.ns = Object.create(parent.ns);
|
|
1071
|
+
}
|
|
1072
|
+
tag.ns[local] = this.attribValue;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
this.attribList.push([this.attribName, this.attribValue]);
|
|
1076
|
+
} else {
|
|
1077
|
+
this.tag.attributes[this.attribName] = this.attribValue;
|
|
1078
|
+
this.emitNode("onattribute", {
|
|
1079
|
+
name: this.attribName,
|
|
1080
|
+
value: this.attribValue
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
this.attribName = this.attribValue = "";
|
|
1084
|
+
}
|
|
1085
|
+
newTag() {
|
|
1086
|
+
if (!this.strict)
|
|
1087
|
+
this.tagName = this.tagName[this.looseCase]();
|
|
1088
|
+
const parent = this.tags[this.tags.length - 1] || this;
|
|
1089
|
+
const tag = this.tag = { name: this.tagName, attributes: {} };
|
|
1090
|
+
if (this.opt.xmlns) {
|
|
1091
|
+
tag.ns = parent.ns;
|
|
1092
|
+
}
|
|
1093
|
+
this.attribList.length = 0;
|
|
1094
|
+
this.emitNode("onopentagstart", tag);
|
|
1095
|
+
}
|
|
1096
|
+
parseEntity() {
|
|
1097
|
+
let entity = this.entity;
|
|
1098
|
+
const entityLC = entity.toLowerCase();
|
|
1099
|
+
let num = NaN;
|
|
1100
|
+
let numStr = "";
|
|
1101
|
+
if (this.ENTITIES[entity]) {
|
|
1102
|
+
return this.ENTITIES[entity];
|
|
1103
|
+
}
|
|
1104
|
+
if (this.ENTITIES[entityLC]) {
|
|
1105
|
+
return this.ENTITIES[entityLC];
|
|
1106
|
+
}
|
|
1107
|
+
entity = entityLC;
|
|
1108
|
+
if (entity.charAt(0) === "#") {
|
|
1109
|
+
if (entity.charAt(1) === "x") {
|
|
1110
|
+
entity = entity.slice(2);
|
|
1111
|
+
num = parseInt(entity, 16);
|
|
1112
|
+
numStr = num.toString(16);
|
|
1113
|
+
} else {
|
|
1114
|
+
entity = entity.slice(1);
|
|
1115
|
+
num = parseInt(entity, 10);
|
|
1116
|
+
numStr = num.toString(10);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
entity = entity.replace(/^0+/, "");
|
|
1120
|
+
if (isNaN(num) || numStr.toLowerCase() !== entity) {
|
|
1121
|
+
this.strictFail("Invalid character entity");
|
|
1122
|
+
return `&${this.entity};`;
|
|
1123
|
+
}
|
|
1124
|
+
return String.fromCodePoint(num);
|
|
1125
|
+
}
|
|
1126
|
+
beginWhiteSpace(c) {
|
|
1127
|
+
if (c === "<") {
|
|
1128
|
+
this.state = this.S.OPEN_WAKA;
|
|
1129
|
+
this.startTagPosition = this.position;
|
|
1130
|
+
} else if (!SAX.isWhitespace(c)) {
|
|
1131
|
+
this.strictFail("Non-whitespace before first tag.");
|
|
1132
|
+
this.textNode = c;
|
|
1133
|
+
this.state = this.S.TEXT;
|
|
1134
|
+
} else {
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
strictFail(message) {
|
|
1138
|
+
if (typeof this !== "object" || !(this instanceof SAXParser)) {
|
|
1139
|
+
throw new Error("bad call to strictFail");
|
|
1140
|
+
}
|
|
1141
|
+
if (this.strict) {
|
|
1142
|
+
this.errorFunction(message);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
textApplyOptions(text) {
|
|
1146
|
+
if (this.opt.trim)
|
|
1147
|
+
text = text.trim();
|
|
1148
|
+
if (this.opt.normalize)
|
|
1149
|
+
text = text.replace(/\s+/g, " ");
|
|
1150
|
+
return text;
|
|
1151
|
+
}
|
|
1152
|
+
emitNode(nodeType, data) {
|
|
1153
|
+
if (this.textNode)
|
|
1154
|
+
this.closeText();
|
|
1155
|
+
this.emit(nodeType, data);
|
|
1156
|
+
}
|
|
1157
|
+
closeText() {
|
|
1158
|
+
this.textNode = this.textApplyOptions(this.textNode);
|
|
1159
|
+
if (this.textNode !== void 0 && this.textNode !== "" && this.textNode !== "undefined") {
|
|
1160
|
+
this.emit("ontext", this.textNode);
|
|
1161
|
+
}
|
|
1162
|
+
this.textNode = "";
|
|
1163
|
+
}
|
|
1164
|
+
checkBufferLength() {
|
|
1165
|
+
const maxAllowed = Math.max(this.opt.MAX_BUFFER_LENGTH, 10);
|
|
1166
|
+
let maxActual = 0;
|
|
1167
|
+
for (let i = 0, l = this.BUFFERS.length; i < l; i++) {
|
|
1168
|
+
const len = this[this.BUFFERS[i]]?.length || 0;
|
|
1169
|
+
if (len > maxAllowed) {
|
|
1170
|
+
switch (this.BUFFERS[i]) {
|
|
1171
|
+
case "textNode":
|
|
1172
|
+
this.closeText();
|
|
1173
|
+
break;
|
|
1174
|
+
case "cdata":
|
|
1175
|
+
this.emitNode("oncdata", this.cdata);
|
|
1176
|
+
this.cdata = "";
|
|
1177
|
+
break;
|
|
1178
|
+
case "script":
|
|
1179
|
+
this.emitNode("onscript", this.script);
|
|
1180
|
+
this.script = "";
|
|
1181
|
+
break;
|
|
1182
|
+
default:
|
|
1183
|
+
this.errorFunction(`Max buffer length exceeded: ${this.BUFFERS[i]}`);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
maxActual = Math.max(maxActual, len);
|
|
1187
|
+
}
|
|
1188
|
+
const m = this.opt.MAX_BUFFER_LENGTH - maxActual;
|
|
1189
|
+
this.bufferCheckPosition = m + this.position;
|
|
1190
|
+
}
|
|
1191
|
+
openTag(selfClosing) {
|
|
1192
|
+
if (this.opt.xmlns) {
|
|
1193
|
+
const tag = this.tag;
|
|
1194
|
+
const qn = SAX.qname(this.tagName);
|
|
1195
|
+
tag.prefix = qn.prefix;
|
|
1196
|
+
tag.local = qn.local;
|
|
1197
|
+
tag.uri = tag.ns[qn.prefix] || "";
|
|
1198
|
+
if (tag.prefix && !tag.uri) {
|
|
1199
|
+
this.strictFail(`Unbound namespace prefix: ${JSON.stringify(this.tagName)}`);
|
|
1200
|
+
tag.uri = qn.prefix;
|
|
1201
|
+
}
|
|
1202
|
+
const parent = this.tags[this.tags.length - 1] || this;
|
|
1203
|
+
if (tag.ns && parent.ns !== tag.ns) {
|
|
1204
|
+
const that = this;
|
|
1205
|
+
Object.keys(tag.ns).forEach((p) => {
|
|
1206
|
+
that.emitNode("onopennamespace", {
|
|
1207
|
+
prefix: p,
|
|
1208
|
+
uri: tag.ns[p]
|
|
1209
|
+
});
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
for (let i = 0, l = this.attribList.length; i < l; i++) {
|
|
1213
|
+
const nv = this.attribList[i];
|
|
1214
|
+
const name = nv[0];
|
|
1215
|
+
const value = nv[1];
|
|
1216
|
+
const qualName = SAX.qname(name, true);
|
|
1217
|
+
const prefix = qualName.prefix;
|
|
1218
|
+
const local = qualName.local;
|
|
1219
|
+
const uri = prefix === "" ? "" : tag.ns[prefix] || "";
|
|
1220
|
+
const a = {
|
|
1221
|
+
name,
|
|
1222
|
+
value,
|
|
1223
|
+
prefix,
|
|
1224
|
+
local,
|
|
1225
|
+
uri
|
|
1226
|
+
};
|
|
1227
|
+
if (prefix && prefix !== "xmlns" && !uri) {
|
|
1228
|
+
this.strictFail(`Unbound namespace prefix: ${JSON.stringify(prefix)}`);
|
|
1229
|
+
a.uri = prefix;
|
|
1230
|
+
}
|
|
1231
|
+
this.tag.attributes[name] = a;
|
|
1232
|
+
this.emitNode("onattribute", a);
|
|
1233
|
+
}
|
|
1234
|
+
this.attribList.length = 0;
|
|
1235
|
+
}
|
|
1236
|
+
this.tag.isSelfClosing = Boolean(selfClosing);
|
|
1237
|
+
this.sawRoot = true;
|
|
1238
|
+
this.tags.push(this.tag);
|
|
1239
|
+
this.emitNode("onopentag", this.tag);
|
|
1240
|
+
if (!selfClosing) {
|
|
1241
|
+
if (!this.noscript && this.tagName.toLowerCase() === "script") {
|
|
1242
|
+
this.state = this.S.SCRIPT;
|
|
1243
|
+
} else {
|
|
1244
|
+
this.state = this.S.TEXT;
|
|
1245
|
+
}
|
|
1246
|
+
this.tag = null;
|
|
1247
|
+
this.tagName = "";
|
|
1248
|
+
}
|
|
1249
|
+
this.attribName = this.attribValue = "";
|
|
1250
|
+
this.attribList.length = 0;
|
|
1251
|
+
}
|
|
1252
|
+
closeTag() {
|
|
1253
|
+
if (!this.tagName) {
|
|
1254
|
+
this.strictFail("Weird empty close tag.");
|
|
1255
|
+
this.textNode += "</>";
|
|
1256
|
+
this.state = this.S.TEXT;
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
if (this.script) {
|
|
1260
|
+
if (this.tagName !== "script") {
|
|
1261
|
+
this.script += `</${this.tagName}>`;
|
|
1262
|
+
this.tagName = "";
|
|
1263
|
+
this.state = this.S.SCRIPT;
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
this.emitNode("onscript", this.script);
|
|
1267
|
+
this.script = "";
|
|
1268
|
+
}
|
|
1269
|
+
let t = this.tags.length;
|
|
1270
|
+
let tagName = this.tagName;
|
|
1271
|
+
if (!this.strict) {
|
|
1272
|
+
tagName = tagName[this.looseCase]();
|
|
1273
|
+
}
|
|
1274
|
+
while (t--) {
|
|
1275
|
+
const close = this.tags[t];
|
|
1276
|
+
if (close.name !== tagName) {
|
|
1277
|
+
this.strictFail("Unexpected close tag");
|
|
1278
|
+
} else {
|
|
1279
|
+
break;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
if (t < 0) {
|
|
1283
|
+
this.strictFail(`Unmatched closing tag: ${this.tagName}`);
|
|
1284
|
+
this.textNode += `</${this.tagName}>`;
|
|
1285
|
+
this.state = this.S.TEXT;
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
this.tagName = tagName;
|
|
1289
|
+
let s = this.tags.length;
|
|
1290
|
+
while (s-- > t) {
|
|
1291
|
+
const tag = this.tag = this.tags.pop();
|
|
1292
|
+
this.tagName = this.tag.name;
|
|
1293
|
+
this.emitNode("onclosetag", this.tagName);
|
|
1294
|
+
const x = {};
|
|
1295
|
+
for (const i in tag.ns) {
|
|
1296
|
+
if (tag.ns.hasOwnProperty(i)) {
|
|
1297
|
+
x[i] = tag.ns[i];
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
const parent = this.tags[this.tags.length - 1] || this;
|
|
1301
|
+
if (this.opt.xmlns && tag.ns !== parent.ns) {
|
|
1302
|
+
const that = this;
|
|
1303
|
+
Object.keys(tag.ns).forEach((p) => {
|
|
1304
|
+
const n = tag.ns[p];
|
|
1305
|
+
that.emitNode("onclosenamespace", { prefix: p, uri: n });
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
if (t === 0)
|
|
1310
|
+
this.closedRoot = true;
|
|
1311
|
+
this.tagName = this.attribValue = this.attribName = "";
|
|
1312
|
+
this.attribList.length = 0;
|
|
1313
|
+
this.state = this.S.TEXT;
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1316
|
+
SAXParser = class extends SAX {
|
|
1317
|
+
constructor(opt) {
|
|
1318
|
+
super();
|
|
1319
|
+
this.opt = DEFAULT_SAX_PARSER_OPTIONS;
|
|
1320
|
+
this.events = DEFAULT_SAX_EVENTS;
|
|
1321
|
+
this.clearBuffers();
|
|
1322
|
+
this.opt = opt = { ...this.opt, ...opt };
|
|
1323
|
+
this.events = { ...this.events, ...opt };
|
|
1324
|
+
this.q = this.c = "";
|
|
1325
|
+
this.opt.lowercase = this.opt.lowercase || this.opt.lowercasetags;
|
|
1326
|
+
this.bufferCheckPosition = this.opt.MAX_BUFFER_LENGTH;
|
|
1327
|
+
this.looseCase = this.opt.lowercase ? "toLowerCase" : "toUpperCase";
|
|
1328
|
+
this.tags = [];
|
|
1329
|
+
this.closed = this.closedRoot = this.sawRoot = false;
|
|
1330
|
+
this.tag = this.error = null;
|
|
1331
|
+
this.strict = Boolean(this.opt.strict);
|
|
1332
|
+
this.noscript = Boolean(this.opt.strict || this.opt.noscript);
|
|
1333
|
+
this.state = this.S.BEGIN;
|
|
1334
|
+
this.strictEntities = this.opt.strictEntities;
|
|
1335
|
+
this.ENTITIES = this.strictEntities ? Object.create(this.XML_ENTITIES) : Object.create(this.ENTITIES);
|
|
1336
|
+
this.attribList = [];
|
|
1337
|
+
if (this.opt.xmlns) {
|
|
1338
|
+
this.ns = Object.create(this.rootNS);
|
|
1339
|
+
}
|
|
1340
|
+
this.trackPosition = this.opt.position !== false;
|
|
1341
|
+
if (this.trackPosition) {
|
|
1342
|
+
this.position = this.line = this.column = 0;
|
|
1343
|
+
}
|
|
1344
|
+
this.emit("onready");
|
|
1345
|
+
}
|
|
1346
|
+
resume() {
|
|
1347
|
+
this.error = null;
|
|
1348
|
+
return this;
|
|
1349
|
+
}
|
|
1350
|
+
close() {
|
|
1351
|
+
return this.write(null);
|
|
1352
|
+
}
|
|
1353
|
+
flush() {
|
|
1354
|
+
this.flushBuffers();
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
SAXParser.ENTITIES = ENTITIES;
|
|
1358
|
+
}
|
|
1359
|
+
});
|
|
1360
|
+
|
|
1361
|
+
// node_modules/fast-xml-parser/src/util.js
|
|
1362
|
+
var require_util = __commonJS({
|
|
1363
|
+
"node_modules/fast-xml-parser/src/util.js"(exports) {
|
|
1364
|
+
"use strict";
|
|
1365
|
+
var nameStartChar = ":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
|
|
1366
|
+
var nameChar = nameStartChar + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
|
|
1367
|
+
var nameRegexp = "[" + nameStartChar + "][" + nameChar + "]*";
|
|
1368
|
+
var regexName = new RegExp("^" + nameRegexp + "$");
|
|
1369
|
+
var getAllMatches = function(string, regex) {
|
|
1370
|
+
const matches = [];
|
|
1371
|
+
let match = regex.exec(string);
|
|
1372
|
+
while (match) {
|
|
1373
|
+
const allmatches = [];
|
|
1374
|
+
allmatches.startIndex = regex.lastIndex - match[0].length;
|
|
1375
|
+
const len = match.length;
|
|
1376
|
+
for (let index = 0; index < len; index++) {
|
|
1377
|
+
allmatches.push(match[index]);
|
|
1378
|
+
}
|
|
1379
|
+
matches.push(allmatches);
|
|
1380
|
+
match = regex.exec(string);
|
|
1381
|
+
}
|
|
1382
|
+
return matches;
|
|
1383
|
+
};
|
|
1384
|
+
var isName = function(string) {
|
|
1385
|
+
const match = regexName.exec(string);
|
|
1386
|
+
return !(match === null || typeof match === "undefined");
|
|
1387
|
+
};
|
|
1388
|
+
exports.isExist = function(v) {
|
|
1389
|
+
return typeof v !== "undefined";
|
|
1390
|
+
};
|
|
1391
|
+
exports.isEmptyObject = function(obj) {
|
|
1392
|
+
return Object.keys(obj).length === 0;
|
|
1393
|
+
};
|
|
1394
|
+
exports.merge = function(target, a, arrayMode) {
|
|
1395
|
+
if (a) {
|
|
1396
|
+
const keys = Object.keys(a);
|
|
1397
|
+
const len = keys.length;
|
|
1398
|
+
for (let i = 0; i < len; i++) {
|
|
1399
|
+
if (arrayMode === "strict") {
|
|
1400
|
+
target[keys[i]] = [a[keys[i]]];
|
|
1401
|
+
} else {
|
|
1402
|
+
target[keys[i]] = a[keys[i]];
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
};
|
|
1407
|
+
exports.getValue = function(v) {
|
|
1408
|
+
if (exports.isExist(v)) {
|
|
1409
|
+
return v;
|
|
1410
|
+
} else {
|
|
1411
|
+
return "";
|
|
1412
|
+
}
|
|
1413
|
+
};
|
|
1414
|
+
exports.isName = isName;
|
|
1415
|
+
exports.getAllMatches = getAllMatches;
|
|
1416
|
+
exports.nameRegexp = nameRegexp;
|
|
1417
|
+
}
|
|
1418
|
+
});
|
|
1419
|
+
|
|
1420
|
+
// node_modules/fast-xml-parser/src/validator.js
|
|
1421
|
+
var require_validator = __commonJS({
|
|
1422
|
+
"node_modules/fast-xml-parser/src/validator.js"(exports) {
|
|
1423
|
+
"use strict";
|
|
1424
|
+
var util = require_util();
|
|
1425
|
+
var defaultOptions = {
|
|
1426
|
+
allowBooleanAttributes: false,
|
|
1427
|
+
unpairedTags: []
|
|
1428
|
+
};
|
|
1429
|
+
exports.validate = function(xmlData, options) {
|
|
1430
|
+
options = Object.assign({}, defaultOptions, options);
|
|
1431
|
+
const tags = [];
|
|
1432
|
+
let tagFound = false;
|
|
1433
|
+
let reachedRoot = false;
|
|
1434
|
+
if (xmlData[0] === "\uFEFF") {
|
|
1435
|
+
xmlData = xmlData.substr(1);
|
|
1436
|
+
}
|
|
1437
|
+
for (let i = 0; i < xmlData.length; i++) {
|
|
1438
|
+
if (xmlData[i] === "<" && xmlData[i + 1] === "?") {
|
|
1439
|
+
i += 2;
|
|
1440
|
+
i = readPI(xmlData, i);
|
|
1441
|
+
if (i.err)
|
|
1442
|
+
return i;
|
|
1443
|
+
} else if (xmlData[i] === "<") {
|
|
1444
|
+
let tagStartPos = i;
|
|
1445
|
+
i++;
|
|
1446
|
+
if (xmlData[i] === "!") {
|
|
1447
|
+
i = readCommentAndCDATA(xmlData, i);
|
|
1448
|
+
continue;
|
|
1449
|
+
} else {
|
|
1450
|
+
let closingTag = false;
|
|
1451
|
+
if (xmlData[i] === "/") {
|
|
1452
|
+
closingTag = true;
|
|
1453
|
+
i++;
|
|
1454
|
+
}
|
|
1455
|
+
let tagName = "";
|
|
1456
|
+
for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== "\n" && xmlData[i] !== "\r"; i++) {
|
|
1457
|
+
tagName += xmlData[i];
|
|
1458
|
+
}
|
|
1459
|
+
tagName = tagName.trim();
|
|
1460
|
+
if (tagName[tagName.length - 1] === "/") {
|
|
1461
|
+
tagName = tagName.substring(0, tagName.length - 1);
|
|
1462
|
+
i--;
|
|
1463
|
+
}
|
|
1464
|
+
if (!validateTagName(tagName)) {
|
|
1465
|
+
let msg;
|
|
1466
|
+
if (tagName.trim().length === 0) {
|
|
1467
|
+
msg = "Invalid space after '<'.";
|
|
1468
|
+
} else {
|
|
1469
|
+
msg = "Tag '" + tagName + "' is an invalid name.";
|
|
1470
|
+
}
|
|
1471
|
+
return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i));
|
|
1472
|
+
}
|
|
1473
|
+
const result = readAttributeStr(xmlData, i);
|
|
1474
|
+
if (result === false) {
|
|
1475
|
+
return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
|
|
1476
|
+
}
|
|
1477
|
+
let attrStr = result.value;
|
|
1478
|
+
i = result.index;
|
|
1479
|
+
if (attrStr[attrStr.length - 1] === "/") {
|
|
1480
|
+
const attrStrStart = i - attrStr.length;
|
|
1481
|
+
attrStr = attrStr.substring(0, attrStr.length - 1);
|
|
1482
|
+
const isValid = validateAttributeString(attrStr, options);
|
|
1483
|
+
if (isValid === true) {
|
|
1484
|
+
tagFound = true;
|
|
1485
|
+
} else {
|
|
1486
|
+
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
|
|
1487
|
+
}
|
|
1488
|
+
} else if (closingTag) {
|
|
1489
|
+
if (!result.tagClosed) {
|
|
1490
|
+
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
|
|
1491
|
+
} else if (attrStr.trim().length > 0) {
|
|
1492
|
+
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
1493
|
+
} else {
|
|
1494
|
+
const otg = tags.pop();
|
|
1495
|
+
if (tagName !== otg.tagName) {
|
|
1496
|
+
let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
|
|
1497
|
+
return getErrorObject("InvalidTag", "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
1498
|
+
}
|
|
1499
|
+
if (tags.length == 0) {
|
|
1500
|
+
reachedRoot = true;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
} else {
|
|
1504
|
+
const isValid = validateAttributeString(attrStr, options);
|
|
1505
|
+
if (isValid !== true) {
|
|
1506
|
+
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
|
|
1507
|
+
}
|
|
1508
|
+
if (reachedRoot === true) {
|
|
1509
|
+
return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i));
|
|
1510
|
+
} else if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1511
|
+
} else {
|
|
1512
|
+
tags.push({ tagName, tagStartPos });
|
|
1513
|
+
}
|
|
1514
|
+
tagFound = true;
|
|
1515
|
+
}
|
|
1516
|
+
for (i++; i < xmlData.length; i++) {
|
|
1517
|
+
if (xmlData[i] === "<") {
|
|
1518
|
+
if (xmlData[i + 1] === "!") {
|
|
1519
|
+
i++;
|
|
1520
|
+
i = readCommentAndCDATA(xmlData, i);
|
|
1521
|
+
continue;
|
|
1522
|
+
} else if (xmlData[i + 1] === "?") {
|
|
1523
|
+
i = readPI(xmlData, ++i);
|
|
1524
|
+
if (i.err)
|
|
1525
|
+
return i;
|
|
1526
|
+
} else {
|
|
1527
|
+
break;
|
|
1528
|
+
}
|
|
1529
|
+
} else if (xmlData[i] === "&") {
|
|
1530
|
+
const afterAmp = validateAmpersand(xmlData, i);
|
|
1531
|
+
if (afterAmp == -1)
|
|
1532
|
+
return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
1533
|
+
i = afterAmp;
|
|
1534
|
+
} else {
|
|
1535
|
+
if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
|
|
1536
|
+
return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i));
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
if (xmlData[i] === "<") {
|
|
1541
|
+
i--;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
} else {
|
|
1545
|
+
if (isWhiteSpace(xmlData[i])) {
|
|
1546
|
+
continue;
|
|
1547
|
+
}
|
|
1548
|
+
return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
if (!tagFound) {
|
|
1552
|
+
return getErrorObject("InvalidXml", "Start tag expected.", 1);
|
|
1553
|
+
} else if (tags.length == 1) {
|
|
1554
|
+
return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
|
|
1555
|
+
} else if (tags.length > 0) {
|
|
1556
|
+
return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
|
|
1557
|
+
}
|
|
1558
|
+
return true;
|
|
1559
|
+
};
|
|
1560
|
+
function isWhiteSpace(char) {
|
|
1561
|
+
return char === " " || char === " " || char === "\n" || char === "\r";
|
|
1562
|
+
}
|
|
1563
|
+
function readPI(xmlData, i) {
|
|
1564
|
+
const start = i;
|
|
1565
|
+
for (; i < xmlData.length; i++) {
|
|
1566
|
+
if (xmlData[i] == "?" || xmlData[i] == " ") {
|
|
1567
|
+
const tagname = xmlData.substr(start, i - start);
|
|
1568
|
+
if (i > 5 && tagname === "xml") {
|
|
1569
|
+
return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i));
|
|
1570
|
+
} else if (xmlData[i] == "?" && xmlData[i + 1] == ">") {
|
|
1571
|
+
i++;
|
|
1572
|
+
break;
|
|
1573
|
+
} else {
|
|
1574
|
+
continue;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
return i;
|
|
1579
|
+
}
|
|
1580
|
+
function readCommentAndCDATA(xmlData, i) {
|
|
1581
|
+
if (xmlData.length > i + 5 && xmlData[i + 1] === "-" && xmlData[i + 2] === "-") {
|
|
1582
|
+
for (i += 3; i < xmlData.length; i++) {
|
|
1583
|
+
if (xmlData[i] === "-" && xmlData[i + 1] === "-" && xmlData[i + 2] === ">") {
|
|
1584
|
+
i += 2;
|
|
1585
|
+
break;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
} else if (xmlData.length > i + 8 && xmlData[i + 1] === "D" && xmlData[i + 2] === "O" && xmlData[i + 3] === "C" && xmlData[i + 4] === "T" && xmlData[i + 5] === "Y" && xmlData[i + 6] === "P" && xmlData[i + 7] === "E") {
|
|
1589
|
+
let angleBracketsCount = 1;
|
|
1590
|
+
for (i += 8; i < xmlData.length; i++) {
|
|
1591
|
+
if (xmlData[i] === "<") {
|
|
1592
|
+
angleBracketsCount++;
|
|
1593
|
+
} else if (xmlData[i] === ">") {
|
|
1594
|
+
angleBracketsCount--;
|
|
1595
|
+
if (angleBracketsCount === 0) {
|
|
1596
|
+
break;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
} else if (xmlData.length > i + 9 && xmlData[i + 1] === "[" && xmlData[i + 2] === "C" && xmlData[i + 3] === "D" && xmlData[i + 4] === "A" && xmlData[i + 5] === "T" && xmlData[i + 6] === "A" && xmlData[i + 7] === "[") {
|
|
1601
|
+
for (i += 8; i < xmlData.length; i++) {
|
|
1602
|
+
if (xmlData[i] === "]" && xmlData[i + 1] === "]" && xmlData[i + 2] === ">") {
|
|
1603
|
+
i += 2;
|
|
1604
|
+
break;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
return i;
|
|
1609
|
+
}
|
|
1610
|
+
var doubleQuote = '"';
|
|
1611
|
+
var singleQuote = "'";
|
|
1612
|
+
function readAttributeStr(xmlData, i) {
|
|
1613
|
+
let attrStr = "";
|
|
1614
|
+
let startChar = "";
|
|
1615
|
+
let tagClosed = false;
|
|
1616
|
+
for (; i < xmlData.length; i++) {
|
|
1617
|
+
if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
|
|
1618
|
+
if (startChar === "") {
|
|
1619
|
+
startChar = xmlData[i];
|
|
1620
|
+
} else if (startChar !== xmlData[i]) {
|
|
1621
|
+
} else {
|
|
1622
|
+
startChar = "";
|
|
1623
|
+
}
|
|
1624
|
+
} else if (xmlData[i] === ">") {
|
|
1625
|
+
if (startChar === "") {
|
|
1626
|
+
tagClosed = true;
|
|
1627
|
+
break;
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
attrStr += xmlData[i];
|
|
1631
|
+
}
|
|
1632
|
+
if (startChar !== "") {
|
|
1633
|
+
return false;
|
|
1634
|
+
}
|
|
1635
|
+
return {
|
|
1636
|
+
value: attrStr,
|
|
1637
|
+
index: i,
|
|
1638
|
+
tagClosed
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
var validAttrStrRegxp = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
|
|
1642
|
+
function validateAttributeString(attrStr, options) {
|
|
1643
|
+
const matches = util.getAllMatches(attrStr, validAttrStrRegxp);
|
|
1644
|
+
const attrNames = {};
|
|
1645
|
+
for (let i = 0; i < matches.length; i++) {
|
|
1646
|
+
if (matches[i][1].length === 0) {
|
|
1647
|
+
return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i]));
|
|
1648
|
+
} else if (matches[i][3] !== void 0 && matches[i][4] === void 0) {
|
|
1649
|
+
return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i]));
|
|
1650
|
+
} else if (matches[i][3] === void 0 && !options.allowBooleanAttributes) {
|
|
1651
|
+
return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
|
|
1652
|
+
}
|
|
1653
|
+
const attrName = matches[i][2];
|
|
1654
|
+
if (!validateAttrName(attrName)) {
|
|
1655
|
+
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
|
|
1656
|
+
}
|
|
1657
|
+
if (!attrNames.hasOwnProperty(attrName)) {
|
|
1658
|
+
attrNames[attrName] = 1;
|
|
1659
|
+
} else {
|
|
1660
|
+
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
return true;
|
|
1664
|
+
}
|
|
1665
|
+
function validateNumberAmpersand(xmlData, i) {
|
|
1666
|
+
let re = /\d/;
|
|
1667
|
+
if (xmlData[i] === "x") {
|
|
1668
|
+
i++;
|
|
1669
|
+
re = /[\da-fA-F]/;
|
|
1670
|
+
}
|
|
1671
|
+
for (; i < xmlData.length; i++) {
|
|
1672
|
+
if (xmlData[i] === ";")
|
|
1673
|
+
return i;
|
|
1674
|
+
if (!xmlData[i].match(re))
|
|
1675
|
+
break;
|
|
1676
|
+
}
|
|
1677
|
+
return -1;
|
|
1678
|
+
}
|
|
1679
|
+
function validateAmpersand(xmlData, i) {
|
|
1680
|
+
i++;
|
|
1681
|
+
if (xmlData[i] === ";")
|
|
1682
|
+
return -1;
|
|
1683
|
+
if (xmlData[i] === "#") {
|
|
1684
|
+
i++;
|
|
1685
|
+
return validateNumberAmpersand(xmlData, i);
|
|
1686
|
+
}
|
|
1687
|
+
let count = 0;
|
|
1688
|
+
for (; i < xmlData.length; i++, count++) {
|
|
1689
|
+
if (xmlData[i].match(/\w/) && count < 20)
|
|
1690
|
+
continue;
|
|
1691
|
+
if (xmlData[i] === ";")
|
|
1692
|
+
break;
|
|
1693
|
+
return -1;
|
|
1694
|
+
}
|
|
1695
|
+
return i;
|
|
1696
|
+
}
|
|
1697
|
+
function getErrorObject(code, message, lineNumber) {
|
|
1698
|
+
return {
|
|
1699
|
+
err: {
|
|
1700
|
+
code,
|
|
1701
|
+
msg: message,
|
|
1702
|
+
line: lineNumber.line || lineNumber,
|
|
1703
|
+
col: lineNumber.col
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
function validateAttrName(attrName) {
|
|
1708
|
+
return util.isName(attrName);
|
|
1709
|
+
}
|
|
1710
|
+
function validateTagName(tagname) {
|
|
1711
|
+
return util.isName(tagname);
|
|
1712
|
+
}
|
|
1713
|
+
function getLineNumberForPosition(xmlData, index) {
|
|
1714
|
+
const lines = xmlData.substring(0, index).split(/\r?\n/);
|
|
1715
|
+
return {
|
|
1716
|
+
line: lines.length,
|
|
1717
|
+
col: lines[lines.length - 1].length + 1
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1720
|
+
function getPositionFromMatch(match) {
|
|
1721
|
+
return match.startIndex + match[1].length;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
});
|
|
1725
|
+
|
|
1726
|
+
// node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js
|
|
1727
|
+
var require_OptionsBuilder = __commonJS({
|
|
1728
|
+
"node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js"(exports) {
|
|
1729
|
+
var defaultOptions = {
|
|
1730
|
+
preserveOrder: false,
|
|
1731
|
+
attributeNamePrefix: "@_",
|
|
1732
|
+
attributesGroupName: false,
|
|
1733
|
+
textNodeName: "#text",
|
|
1734
|
+
ignoreAttributes: true,
|
|
1735
|
+
removeNSPrefix: false,
|
|
1736
|
+
allowBooleanAttributes: false,
|
|
1737
|
+
parseTagValue: true,
|
|
1738
|
+
parseAttributeValue: false,
|
|
1739
|
+
trimValues: true,
|
|
1740
|
+
cdataPropName: false,
|
|
1741
|
+
numberParseOptions: {
|
|
1742
|
+
hex: true,
|
|
1743
|
+
leadingZeros: true
|
|
1744
|
+
},
|
|
1745
|
+
tagValueProcessor: function(tagName, val) {
|
|
1746
|
+
return val;
|
|
1747
|
+
},
|
|
1748
|
+
attributeValueProcessor: function(attrName, val) {
|
|
1749
|
+
return val;
|
|
1750
|
+
},
|
|
1751
|
+
stopNodes: [],
|
|
1752
|
+
alwaysCreateTextNode: false,
|
|
1753
|
+
isArray: () => false,
|
|
1754
|
+
commentPropName: false,
|
|
1755
|
+
unpairedTags: [],
|
|
1756
|
+
processEntities: true,
|
|
1757
|
+
htmlEntities: false,
|
|
1758
|
+
ignoreDeclaration: false,
|
|
1759
|
+
ignorePiTags: false,
|
|
1760
|
+
transformTagName: false
|
|
1761
|
+
};
|
|
1762
|
+
var buildOptions = function(options) {
|
|
1763
|
+
return Object.assign({}, defaultOptions, options);
|
|
1764
|
+
};
|
|
1765
|
+
exports.buildOptions = buildOptions;
|
|
1766
|
+
exports.defaultOptions = defaultOptions;
|
|
1767
|
+
}
|
|
1768
|
+
});
|
|
1769
|
+
|
|
1770
|
+
// node_modules/fast-xml-parser/src/xmlparser/xmlNode.js
|
|
1771
|
+
var require_xmlNode = __commonJS({
|
|
1772
|
+
"node_modules/fast-xml-parser/src/xmlparser/xmlNode.js"(exports, module) {
|
|
1773
|
+
"use strict";
|
|
1774
|
+
var XmlNode = class {
|
|
1775
|
+
constructor(tagname) {
|
|
1776
|
+
this.tagname = tagname;
|
|
1777
|
+
this.child = [];
|
|
1778
|
+
this[":@"] = {};
|
|
1779
|
+
}
|
|
1780
|
+
add(key, val) {
|
|
1781
|
+
this.child.push({ [key]: val });
|
|
1782
|
+
}
|
|
1783
|
+
addChild(node) {
|
|
1784
|
+
if (node[":@"] && Object.keys(node[":@"]).length > 0) {
|
|
1785
|
+
this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] });
|
|
1786
|
+
} else {
|
|
1787
|
+
this.child.push({ [node.tagname]: node.child });
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
};
|
|
1791
|
+
module.exports = XmlNode;
|
|
1792
|
+
}
|
|
1793
|
+
});
|
|
1794
|
+
|
|
1795
|
+
// node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js
|
|
1796
|
+
var require_DocTypeReader = __commonJS({
|
|
1797
|
+
"node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js"(exports, module) {
|
|
1798
|
+
function readDocType(xmlData, i) {
|
|
1799
|
+
const entities = {};
|
|
1800
|
+
if (xmlData[i + 3] === "O" && xmlData[i + 4] === "C" && xmlData[i + 5] === "T" && xmlData[i + 6] === "Y" && xmlData[i + 7] === "P" && xmlData[i + 8] === "E") {
|
|
1801
|
+
i = i + 9;
|
|
1802
|
+
let angleBracketsCount = 1;
|
|
1803
|
+
let hasBody = false, entity = false, comment = false;
|
|
1804
|
+
let exp = "";
|
|
1805
|
+
for (; i < xmlData.length; i++) {
|
|
1806
|
+
if (xmlData[i] === "<") {
|
|
1807
|
+
if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "N" && xmlData[i + 4] === "T" && xmlData[i + 5] === "I" && xmlData[i + 6] === "T" && xmlData[i + 7] === "Y") {
|
|
1808
|
+
i += 7;
|
|
1809
|
+
entity = true;
|
|
1810
|
+
} else if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "L" && xmlData[i + 4] === "E" && xmlData[i + 5] === "M" && xmlData[i + 6] === "E" && xmlData[i + 7] === "N" && xmlData[i + 8] === "T") {
|
|
1811
|
+
i += 8;
|
|
1812
|
+
} else if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "A" && xmlData[i + 3] === "T" && xmlData[i + 4] === "T" && xmlData[i + 5] === "L" && xmlData[i + 6] === "I" && xmlData[i + 7] === "S" && xmlData[i + 8] === "T") {
|
|
1813
|
+
i += 8;
|
|
1814
|
+
} else if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "N" && xmlData[i + 3] === "O" && xmlData[i + 4] === "T" && xmlData[i + 5] === "A" && xmlData[i + 6] === "T" && xmlData[i + 7] === "I" && xmlData[i + 8] === "O" && xmlData[i + 9] === "N") {
|
|
1815
|
+
i += 9;
|
|
1816
|
+
} else if (xmlData[i + 1] === "!" && xmlData[i + 2] === "-" && xmlData[i + 3] === "-") {
|
|
1817
|
+
comment = true;
|
|
1818
|
+
} else {
|
|
1819
|
+
throw new Error("Invalid DOCTYPE");
|
|
1820
|
+
}
|
|
1821
|
+
angleBracketsCount++;
|
|
1822
|
+
exp = "";
|
|
1823
|
+
} else if (xmlData[i] === ">") {
|
|
1824
|
+
if (comment) {
|
|
1825
|
+
if (xmlData[i - 1] === "-" && xmlData[i - 2] === "-") {
|
|
1826
|
+
comment = false;
|
|
1827
|
+
} else {
|
|
1828
|
+
throw new Error(`Invalid XML comment in DOCTYPE`);
|
|
1829
|
+
}
|
|
1830
|
+
} else if (entity) {
|
|
1831
|
+
parseEntityExp(exp, entities);
|
|
1832
|
+
entity = false;
|
|
1833
|
+
}
|
|
1834
|
+
angleBracketsCount--;
|
|
1835
|
+
if (angleBracketsCount === 0) {
|
|
1836
|
+
break;
|
|
1837
|
+
}
|
|
1838
|
+
} else if (xmlData[i] === "[") {
|
|
1839
|
+
hasBody = true;
|
|
1840
|
+
} else {
|
|
1841
|
+
exp += xmlData[i];
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
if (angleBracketsCount !== 0) {
|
|
1845
|
+
throw new Error(`Unclosed DOCTYPE`);
|
|
1846
|
+
}
|
|
1847
|
+
} else {
|
|
1848
|
+
throw new Error(`Invalid Tag instead of DOCTYPE`);
|
|
1849
|
+
}
|
|
1850
|
+
return { entities, i };
|
|
1851
|
+
}
|
|
1852
|
+
var entityRegex = RegExp(`^\\s([a-zA-z0-0]+)[ ](['"])([^&]+)\\2`);
|
|
1853
|
+
function parseEntityExp(exp, entities) {
|
|
1854
|
+
const match = entityRegex.exec(exp);
|
|
1855
|
+
if (match) {
|
|
1856
|
+
entities[match[1]] = {
|
|
1857
|
+
regx: RegExp(`&${match[1]};`, "g"),
|
|
1858
|
+
val: match[3]
|
|
1859
|
+
};
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
module.exports = readDocType;
|
|
1863
|
+
}
|
|
1864
|
+
});
|
|
1865
|
+
|
|
1866
|
+
// ../../node_modules/strnum/strnum.js
|
|
1867
|
+
var require_strnum = __commonJS({
|
|
1868
|
+
"../../node_modules/strnum/strnum.js"(exports, module) {
|
|
1869
|
+
var hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
|
1870
|
+
var numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
|
|
1871
|
+
if (!Number.parseInt && window.parseInt) {
|
|
1872
|
+
Number.parseInt = window.parseInt;
|
|
1873
|
+
}
|
|
1874
|
+
if (!Number.parseFloat && window.parseFloat) {
|
|
1875
|
+
Number.parseFloat = window.parseFloat;
|
|
1876
|
+
}
|
|
1877
|
+
var consider = {
|
|
1878
|
+
hex: true,
|
|
1879
|
+
leadingZeros: true,
|
|
1880
|
+
decimalPoint: ".",
|
|
1881
|
+
eNotation: true
|
|
1882
|
+
};
|
|
1883
|
+
function toNumber(str, options = {}) {
|
|
1884
|
+
options = Object.assign({}, consider, options);
|
|
1885
|
+
if (!str || typeof str !== "string")
|
|
1886
|
+
return str;
|
|
1887
|
+
let trimmedStr = str.trim();
|
|
1888
|
+
if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr))
|
|
1889
|
+
return str;
|
|
1890
|
+
else if (options.hex && hexRegex.test(trimmedStr)) {
|
|
1891
|
+
return Number.parseInt(trimmedStr, 16);
|
|
1892
|
+
} else {
|
|
1893
|
+
const match = numRegex.exec(trimmedStr);
|
|
1894
|
+
if (match) {
|
|
1895
|
+
const sign = match[1];
|
|
1896
|
+
const leadingZeros = match[2];
|
|
1897
|
+
let numTrimmedByZeros = trimZeros(match[3]);
|
|
1898
|
+
const eNotation = match[4] || match[6];
|
|
1899
|
+
if (!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".")
|
|
1900
|
+
return str;
|
|
1901
|
+
else if (!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".")
|
|
1902
|
+
return str;
|
|
1903
|
+
else {
|
|
1904
|
+
const num = Number(trimmedStr);
|
|
1905
|
+
const numStr = "" + num;
|
|
1906
|
+
if (numStr.search(/[eE]/) !== -1) {
|
|
1907
|
+
if (options.eNotation)
|
|
1908
|
+
return num;
|
|
1909
|
+
else
|
|
1910
|
+
return str;
|
|
1911
|
+
} else if (eNotation) {
|
|
1912
|
+
if (options.eNotation)
|
|
1913
|
+
return num;
|
|
1914
|
+
else
|
|
1915
|
+
return str;
|
|
1916
|
+
} else if (trimmedStr.indexOf(".") !== -1) {
|
|
1917
|
+
if (numStr === "0" && numTrimmedByZeros === "")
|
|
1918
|
+
return num;
|
|
1919
|
+
else if (numStr === numTrimmedByZeros)
|
|
1920
|
+
return num;
|
|
1921
|
+
else if (sign && numStr === "-" + numTrimmedByZeros)
|
|
1922
|
+
return num;
|
|
1923
|
+
else
|
|
1924
|
+
return str;
|
|
1925
|
+
}
|
|
1926
|
+
if (leadingZeros) {
|
|
1927
|
+
if (numTrimmedByZeros === numStr)
|
|
1928
|
+
return num;
|
|
1929
|
+
else if (sign + numTrimmedByZeros === numStr)
|
|
1930
|
+
return num;
|
|
1931
|
+
else
|
|
1932
|
+
return str;
|
|
1933
|
+
}
|
|
1934
|
+
if (trimmedStr === numStr)
|
|
1935
|
+
return num;
|
|
1936
|
+
else if (trimmedStr === sign + numStr)
|
|
1937
|
+
return num;
|
|
1938
|
+
return str;
|
|
1939
|
+
}
|
|
1940
|
+
} else {
|
|
1941
|
+
return str;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
function trimZeros(numStr) {
|
|
1946
|
+
if (numStr && numStr.indexOf(".") !== -1) {
|
|
1947
|
+
numStr = numStr.replace(/0+$/, "");
|
|
1948
|
+
if (numStr === ".")
|
|
1949
|
+
numStr = "0";
|
|
1950
|
+
else if (numStr[0] === ".")
|
|
1951
|
+
numStr = "0" + numStr;
|
|
1952
|
+
else if (numStr[numStr.length - 1] === ".")
|
|
1953
|
+
numStr = numStr.substr(0, numStr.length - 1);
|
|
1954
|
+
return numStr;
|
|
1955
|
+
}
|
|
1956
|
+
return numStr;
|
|
1957
|
+
}
|
|
1958
|
+
module.exports = toNumber;
|
|
1959
|
+
}
|
|
1960
|
+
});
|
|
1961
|
+
|
|
1962
|
+
// node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js
|
|
1963
|
+
var require_OrderedObjParser = __commonJS({
|
|
1964
|
+
"node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js"(exports, module) {
|
|
1965
|
+
"use strict";
|
|
1966
|
+
var util = require_util();
|
|
1967
|
+
var xmlNode = require_xmlNode();
|
|
1968
|
+
var readDocType = require_DocTypeReader();
|
|
1969
|
+
var toNumber = require_strnum();
|
|
1970
|
+
var regx = "<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)".replace(/NAME/g, util.nameRegexp);
|
|
1971
|
+
var OrderedObjParser = class {
|
|
1972
|
+
constructor(options) {
|
|
1973
|
+
this.options = options;
|
|
1974
|
+
this.currentNode = null;
|
|
1975
|
+
this.tagsNodeStack = [];
|
|
1976
|
+
this.docTypeEntities = {};
|
|
1977
|
+
this.lastEntities = {
|
|
1978
|
+
"apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
|
|
1979
|
+
"gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
|
|
1980
|
+
"lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
|
|
1981
|
+
"quot": { regex: /&(quot|#34|#x22);/g, val: '"' }
|
|
1982
|
+
};
|
|
1983
|
+
this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" };
|
|
1984
|
+
this.htmlEntities = {
|
|
1985
|
+
"space": { regex: /&(nbsp|#160);/g, val: " " },
|
|
1986
|
+
"cent": { regex: /&(cent|#162);/g, val: "\xA2" },
|
|
1987
|
+
"pound": { regex: /&(pound|#163);/g, val: "\xA3" },
|
|
1988
|
+
"yen": { regex: /&(yen|#165);/g, val: "\xA5" },
|
|
1989
|
+
"euro": { regex: /&(euro|#8364);/g, val: "\u20AC" },
|
|
1990
|
+
"copyright": { regex: /&(copy|#169);/g, val: "\xA9" },
|
|
1991
|
+
"reg": { regex: /&(reg|#174);/g, val: "\xAE" },
|
|
1992
|
+
"inr": { regex: /&(inr|#8377);/g, val: "\u20B9" }
|
|
1993
|
+
};
|
|
1994
|
+
this.addExternalEntities = addExternalEntities;
|
|
1995
|
+
this.parseXml = parseXml;
|
|
1996
|
+
this.parseTextData = parseTextData;
|
|
1997
|
+
this.resolveNameSpace = resolveNameSpace;
|
|
1998
|
+
this.buildAttributesMap = buildAttributesMap;
|
|
1999
|
+
this.isItStopNode = isItStopNode;
|
|
2000
|
+
this.replaceEntitiesValue = replaceEntitiesValue;
|
|
2001
|
+
this.readStopNodeData = readStopNodeData;
|
|
2002
|
+
this.saveTextToParentTag = saveTextToParentTag;
|
|
2003
|
+
}
|
|
2004
|
+
};
|
|
2005
|
+
function addExternalEntities(externalEntities) {
|
|
2006
|
+
const entKeys = Object.keys(externalEntities);
|
|
2007
|
+
for (let i = 0; i < entKeys.length; i++) {
|
|
2008
|
+
const ent = entKeys[i];
|
|
2009
|
+
this.lastEntities[ent] = {
|
|
2010
|
+
regex: new RegExp("&" + ent + ";", "g"),
|
|
2011
|
+
val: externalEntities[ent]
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
|
|
2016
|
+
if (val !== void 0) {
|
|
2017
|
+
if (this.options.trimValues && !dontTrim) {
|
|
2018
|
+
val = val.trim();
|
|
2019
|
+
}
|
|
2020
|
+
if (val.length > 0) {
|
|
2021
|
+
if (!escapeEntities)
|
|
2022
|
+
val = this.replaceEntitiesValue(val);
|
|
2023
|
+
const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode);
|
|
2024
|
+
if (newval === null || newval === void 0) {
|
|
2025
|
+
return val;
|
|
2026
|
+
} else if (typeof newval !== typeof val || newval !== val) {
|
|
2027
|
+
return newval;
|
|
2028
|
+
} else if (this.options.trimValues) {
|
|
2029
|
+
return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
|
|
2030
|
+
} else {
|
|
2031
|
+
const trimmedVal = val.trim();
|
|
2032
|
+
if (trimmedVal === val) {
|
|
2033
|
+
return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
|
|
2034
|
+
} else {
|
|
2035
|
+
return val;
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
function resolveNameSpace(tagname) {
|
|
2042
|
+
if (this.options.removeNSPrefix) {
|
|
2043
|
+
const tags = tagname.split(":");
|
|
2044
|
+
const prefix = tagname.charAt(0) === "/" ? "/" : "";
|
|
2045
|
+
if (tags[0] === "xmlns") {
|
|
2046
|
+
return "";
|
|
2047
|
+
}
|
|
2048
|
+
if (tags.length === 2) {
|
|
2049
|
+
tagname = prefix + tags[1];
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
return tagname;
|
|
2053
|
+
}
|
|
2054
|
+
var attrsRegx = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm");
|
|
2055
|
+
function buildAttributesMap(attrStr, jPath) {
|
|
2056
|
+
if (!this.options.ignoreAttributes && typeof attrStr === "string") {
|
|
2057
|
+
const matches = util.getAllMatches(attrStr, attrsRegx);
|
|
2058
|
+
const len = matches.length;
|
|
2059
|
+
const attrs = {};
|
|
2060
|
+
for (let i = 0; i < len; i++) {
|
|
2061
|
+
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
2062
|
+
let oldVal = matches[i][4];
|
|
2063
|
+
const aName = this.options.attributeNamePrefix + attrName;
|
|
2064
|
+
if (attrName.length) {
|
|
2065
|
+
if (oldVal !== void 0) {
|
|
2066
|
+
if (this.options.trimValues) {
|
|
2067
|
+
oldVal = oldVal.trim();
|
|
2068
|
+
}
|
|
2069
|
+
oldVal = this.replaceEntitiesValue(oldVal);
|
|
2070
|
+
const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);
|
|
2071
|
+
if (newVal === null || newVal === void 0) {
|
|
2072
|
+
attrs[aName] = oldVal;
|
|
2073
|
+
} else if (typeof newVal !== typeof oldVal || newVal !== oldVal) {
|
|
2074
|
+
attrs[aName] = newVal;
|
|
2075
|
+
} else {
|
|
2076
|
+
attrs[aName] = parseValue(oldVal, this.options.parseAttributeValue, this.options.numberParseOptions);
|
|
2077
|
+
}
|
|
2078
|
+
} else if (this.options.allowBooleanAttributes) {
|
|
2079
|
+
attrs[aName] = true;
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
if (!Object.keys(attrs).length) {
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
if (this.options.attributesGroupName) {
|
|
2087
|
+
const attrCollection = {};
|
|
2088
|
+
attrCollection[this.options.attributesGroupName] = attrs;
|
|
2089
|
+
return attrCollection;
|
|
2090
|
+
}
|
|
2091
|
+
return attrs;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
var parseXml = function(xmlData) {
|
|
2095
|
+
xmlData = xmlData.replace(/\r\n?/g, "\n");
|
|
2096
|
+
const xmlObj = new xmlNode("!xml");
|
|
2097
|
+
let currentNode = xmlObj;
|
|
2098
|
+
let textData = "";
|
|
2099
|
+
let jPath = "";
|
|
2100
|
+
for (let i = 0; i < xmlData.length; i++) {
|
|
2101
|
+
const ch = xmlData[i];
|
|
2102
|
+
if (ch === "<") {
|
|
2103
|
+
if (xmlData[i + 1] === "/") {
|
|
2104
|
+
const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
|
|
2105
|
+
let tagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
2106
|
+
if (this.options.removeNSPrefix) {
|
|
2107
|
+
const colonIndex = tagName.indexOf(":");
|
|
2108
|
+
if (colonIndex !== -1) {
|
|
2109
|
+
tagName = tagName.substr(colonIndex + 1);
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
if (this.options.transformTagName) {
|
|
2113
|
+
tagName = this.options.transformTagName(tagName);
|
|
2114
|
+
}
|
|
2115
|
+
if (currentNode) {
|
|
2116
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
2117
|
+
}
|
|
2118
|
+
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
2119
|
+
currentNode = this.tagsNodeStack.pop();
|
|
2120
|
+
textData = "";
|
|
2121
|
+
i = closeIndex;
|
|
2122
|
+
} else if (xmlData[i + 1] === "?") {
|
|
2123
|
+
let tagData = readTagExp(xmlData, i, false, "?>");
|
|
2124
|
+
if (!tagData)
|
|
2125
|
+
throw new Error("Pi Tag is not closed.");
|
|
2126
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
2127
|
+
if (this.options.ignoreDeclaration && tagData.tagName === "?xml" || this.options.ignorePiTags) {
|
|
2128
|
+
} else {
|
|
2129
|
+
const childNode = new xmlNode(tagData.tagName);
|
|
2130
|
+
childNode.add(this.options.textNodeName, "");
|
|
2131
|
+
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) {
|
|
2132
|
+
childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath);
|
|
2133
|
+
}
|
|
2134
|
+
currentNode.addChild(childNode);
|
|
2135
|
+
}
|
|
2136
|
+
i = tagData.closeIndex + 1;
|
|
2137
|
+
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
2138
|
+
const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
|
|
2139
|
+
if (this.options.commentPropName) {
|
|
2140
|
+
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
2141
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
2142
|
+
currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]);
|
|
2143
|
+
}
|
|
2144
|
+
i = endIndex;
|
|
2145
|
+
} else if (xmlData.substr(i + 1, 2) === "!D") {
|
|
2146
|
+
const result = readDocType(xmlData, i);
|
|
2147
|
+
this.docTypeEntities = result.entities;
|
|
2148
|
+
i = result.i;
|
|
2149
|
+
} else if (xmlData.substr(i + 1, 2) === "![") {
|
|
2150
|
+
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
|
|
2151
|
+
const tagExp = xmlData.substring(i + 9, closeIndex);
|
|
2152
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
2153
|
+
if (this.options.cdataPropName) {
|
|
2154
|
+
currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
|
|
2155
|
+
} else {
|
|
2156
|
+
let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
|
|
2157
|
+
if (val == void 0)
|
|
2158
|
+
val = "";
|
|
2159
|
+
currentNode.add(this.options.textNodeName, val);
|
|
2160
|
+
}
|
|
2161
|
+
i = closeIndex + 2;
|
|
2162
|
+
} else {
|
|
2163
|
+
let result = readTagExp(xmlData, i, this.options.removeNSPrefix);
|
|
2164
|
+
let tagName = result.tagName;
|
|
2165
|
+
let tagExp = result.tagExp;
|
|
2166
|
+
let attrExpPresent = result.attrExpPresent;
|
|
2167
|
+
let closeIndex = result.closeIndex;
|
|
2168
|
+
if (this.options.transformTagName) {
|
|
2169
|
+
tagName = this.options.transformTagName(tagName);
|
|
2170
|
+
}
|
|
2171
|
+
if (currentNode && textData) {
|
|
2172
|
+
if (currentNode.tagname !== "!xml") {
|
|
2173
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
if (tagName !== xmlObj.tagname) {
|
|
2177
|
+
jPath += jPath ? "." + tagName : tagName;
|
|
2178
|
+
}
|
|
2179
|
+
const lastTag = currentNode;
|
|
2180
|
+
if (lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1) {
|
|
2181
|
+
currentNode = this.tagsNodeStack.pop();
|
|
2182
|
+
}
|
|
2183
|
+
if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
|
|
2184
|
+
let tagContent = "";
|
|
2185
|
+
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
2186
|
+
i = result.closeIndex;
|
|
2187
|
+
} else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
2188
|
+
i = result.closeIndex;
|
|
2189
|
+
} else {
|
|
2190
|
+
const result2 = this.readStopNodeData(xmlData, tagName, closeIndex + 1);
|
|
2191
|
+
if (!result2)
|
|
2192
|
+
throw new Error(`Unexpected end of ${tagName}`);
|
|
2193
|
+
i = result2.i;
|
|
2194
|
+
tagContent = result2.tagContent;
|
|
2195
|
+
}
|
|
2196
|
+
const childNode = new xmlNode(tagName);
|
|
2197
|
+
if (tagName !== tagExp && attrExpPresent) {
|
|
2198
|
+
childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
|
|
2199
|
+
}
|
|
2200
|
+
if (tagContent) {
|
|
2201
|
+
tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
|
|
2202
|
+
}
|
|
2203
|
+
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
2204
|
+
childNode.add(this.options.textNodeName, tagContent);
|
|
2205
|
+
currentNode.addChild(childNode);
|
|
2206
|
+
} else {
|
|
2207
|
+
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
2208
|
+
if (tagName[tagName.length - 1] === "/") {
|
|
2209
|
+
tagName = tagName.substr(0, tagName.length - 1);
|
|
2210
|
+
tagExp = tagName;
|
|
2211
|
+
} else {
|
|
2212
|
+
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
2213
|
+
}
|
|
2214
|
+
if (this.options.transformTagName) {
|
|
2215
|
+
tagName = this.options.transformTagName(tagName);
|
|
2216
|
+
}
|
|
2217
|
+
const childNode = new xmlNode(tagName);
|
|
2218
|
+
if (tagName !== tagExp && attrExpPresent) {
|
|
2219
|
+
childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
|
|
2220
|
+
}
|
|
2221
|
+
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
2222
|
+
currentNode.addChild(childNode);
|
|
2223
|
+
} else {
|
|
2224
|
+
const childNode = new xmlNode(tagName);
|
|
2225
|
+
this.tagsNodeStack.push(currentNode);
|
|
2226
|
+
if (tagName !== tagExp && attrExpPresent) {
|
|
2227
|
+
childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
|
|
2228
|
+
}
|
|
2229
|
+
currentNode.addChild(childNode);
|
|
2230
|
+
currentNode = childNode;
|
|
2231
|
+
}
|
|
2232
|
+
textData = "";
|
|
2233
|
+
i = closeIndex;
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
} else {
|
|
2237
|
+
textData += xmlData[i];
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
return xmlObj.child;
|
|
2241
|
+
};
|
|
2242
|
+
var replaceEntitiesValue = function(val) {
|
|
2243
|
+
if (this.options.processEntities) {
|
|
2244
|
+
for (let entityName in this.docTypeEntities) {
|
|
2245
|
+
const entity = this.docTypeEntities[entityName];
|
|
2246
|
+
val = val.replace(entity.regx, entity.val);
|
|
2247
|
+
}
|
|
2248
|
+
for (let entityName in this.lastEntities) {
|
|
2249
|
+
const entity = this.lastEntities[entityName];
|
|
2250
|
+
val = val.replace(entity.regex, entity.val);
|
|
2251
|
+
}
|
|
2252
|
+
if (this.options.htmlEntities) {
|
|
2253
|
+
for (let entityName in this.htmlEntities) {
|
|
2254
|
+
const entity = this.htmlEntities[entityName];
|
|
2255
|
+
val = val.replace(entity.regex, entity.val);
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
val = val.replace(this.ampEntity.regex, this.ampEntity.val);
|
|
2259
|
+
}
|
|
2260
|
+
return val;
|
|
2261
|
+
};
|
|
2262
|
+
function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
|
|
2263
|
+
if (textData) {
|
|
2264
|
+
if (isLeafNode === void 0)
|
|
2265
|
+
isLeafNode = Object.keys(currentNode.child).length === 0;
|
|
2266
|
+
textData = this.parseTextData(textData, currentNode.tagname, jPath, false, currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false, isLeafNode);
|
|
2267
|
+
if (textData !== void 0 && textData !== "")
|
|
2268
|
+
currentNode.add(this.options.textNodeName, textData);
|
|
2269
|
+
textData = "";
|
|
2270
|
+
}
|
|
2271
|
+
return textData;
|
|
2272
|
+
}
|
|
2273
|
+
function isItStopNode(stopNodes, jPath, currentTagName) {
|
|
2274
|
+
const allNodesExp = "*." + currentTagName;
|
|
2275
|
+
for (const stopNodePath in stopNodes) {
|
|
2276
|
+
const stopNodeExp = stopNodes[stopNodePath];
|
|
2277
|
+
if (allNodesExp === stopNodeExp || jPath === stopNodeExp)
|
|
2278
|
+
return true;
|
|
2279
|
+
}
|
|
2280
|
+
return false;
|
|
2281
|
+
}
|
|
2282
|
+
function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
|
|
2283
|
+
let attrBoundary;
|
|
2284
|
+
let tagExp = "";
|
|
2285
|
+
for (let index = i; index < xmlData.length; index++) {
|
|
2286
|
+
let ch = xmlData[index];
|
|
2287
|
+
if (attrBoundary) {
|
|
2288
|
+
if (ch === attrBoundary)
|
|
2289
|
+
attrBoundary = "";
|
|
2290
|
+
} else if (ch === '"' || ch === "'") {
|
|
2291
|
+
attrBoundary = ch;
|
|
2292
|
+
} else if (ch === closingChar[0]) {
|
|
2293
|
+
if (closingChar[1]) {
|
|
2294
|
+
if (xmlData[index + 1] === closingChar[1]) {
|
|
2295
|
+
return {
|
|
2296
|
+
data: tagExp,
|
|
2297
|
+
index
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
} else {
|
|
2301
|
+
return {
|
|
2302
|
+
data: tagExp,
|
|
2303
|
+
index
|
|
2304
|
+
};
|
|
2305
|
+
}
|
|
2306
|
+
} else if (ch === " ") {
|
|
2307
|
+
ch = " ";
|
|
2308
|
+
}
|
|
2309
|
+
tagExp += ch;
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
function findClosingIndex(xmlData, str, i, errMsg) {
|
|
2313
|
+
const closingIndex = xmlData.indexOf(str, i);
|
|
2314
|
+
if (closingIndex === -1) {
|
|
2315
|
+
throw new Error(errMsg);
|
|
2316
|
+
} else {
|
|
2317
|
+
return closingIndex + str.length - 1;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
|
|
2321
|
+
const result = tagExpWithClosingIndex(xmlData, i + 1, closingChar);
|
|
2322
|
+
if (!result)
|
|
2323
|
+
return;
|
|
2324
|
+
let tagExp = result.data;
|
|
2325
|
+
const closeIndex = result.index;
|
|
2326
|
+
const separatorIndex = tagExp.search(/\s/);
|
|
2327
|
+
let tagName = tagExp;
|
|
2328
|
+
let attrExpPresent = true;
|
|
2329
|
+
if (separatorIndex !== -1) {
|
|
2330
|
+
tagName = tagExp.substr(0, separatorIndex).replace(/\s\s*$/, "");
|
|
2331
|
+
tagExp = tagExp.substr(separatorIndex + 1);
|
|
2332
|
+
}
|
|
2333
|
+
if (removeNSPrefix) {
|
|
2334
|
+
const colonIndex = tagName.indexOf(":");
|
|
2335
|
+
if (colonIndex !== -1) {
|
|
2336
|
+
tagName = tagName.substr(colonIndex + 1);
|
|
2337
|
+
attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
return {
|
|
2341
|
+
tagName,
|
|
2342
|
+
tagExp,
|
|
2343
|
+
closeIndex,
|
|
2344
|
+
attrExpPresent
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
function readStopNodeData(xmlData, tagName, i) {
|
|
2348
|
+
const startIndex = i;
|
|
2349
|
+
let openTagCount = 1;
|
|
2350
|
+
for (; i < xmlData.length; i++) {
|
|
2351
|
+
if (xmlData[i] === "<") {
|
|
2352
|
+
if (xmlData[i + 1] === "/") {
|
|
2353
|
+
const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
|
|
2354
|
+
let closeTagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
2355
|
+
if (closeTagName === tagName) {
|
|
2356
|
+
openTagCount--;
|
|
2357
|
+
if (openTagCount === 0) {
|
|
2358
|
+
return {
|
|
2359
|
+
tagContent: xmlData.substring(startIndex, i),
|
|
2360
|
+
i: closeIndex
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
i = closeIndex;
|
|
2365
|
+
} else if (xmlData[i + 1] === "?") {
|
|
2366
|
+
const closeIndex = findClosingIndex(xmlData, "?>", i + 1, "StopNode is not closed.");
|
|
2367
|
+
i = closeIndex;
|
|
2368
|
+
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
2369
|
+
const closeIndex = findClosingIndex(xmlData, "-->", i + 3, "StopNode is not closed.");
|
|
2370
|
+
i = closeIndex;
|
|
2371
|
+
} else if (xmlData.substr(i + 1, 2) === "![") {
|
|
2372
|
+
const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
|
|
2373
|
+
i = closeIndex;
|
|
2374
|
+
} else {
|
|
2375
|
+
const tagData = readTagExp(xmlData, i, ">");
|
|
2376
|
+
if (tagData) {
|
|
2377
|
+
const openTagName = tagData && tagData.tagName;
|
|
2378
|
+
if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/") {
|
|
2379
|
+
openTagCount++;
|
|
2380
|
+
}
|
|
2381
|
+
i = tagData.closeIndex;
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
function parseValue(val, shouldParse, options) {
|
|
2388
|
+
if (shouldParse && typeof val === "string") {
|
|
2389
|
+
const newval = val.trim();
|
|
2390
|
+
if (newval === "true")
|
|
2391
|
+
return true;
|
|
2392
|
+
else if (newval === "false")
|
|
2393
|
+
return false;
|
|
2394
|
+
else
|
|
2395
|
+
return toNumber(val, options);
|
|
2396
|
+
} else {
|
|
2397
|
+
if (util.isExist(val)) {
|
|
2398
|
+
return val;
|
|
2399
|
+
} else {
|
|
2400
|
+
return "";
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
module.exports = OrderedObjParser;
|
|
2405
|
+
}
|
|
2406
|
+
});
|
|
2407
|
+
|
|
2408
|
+
// node_modules/fast-xml-parser/src/xmlparser/node2json.js
|
|
2409
|
+
var require_node2json = __commonJS({
|
|
2410
|
+
"node_modules/fast-xml-parser/src/xmlparser/node2json.js"(exports) {
|
|
2411
|
+
"use strict";
|
|
2412
|
+
function prettify(node, options) {
|
|
2413
|
+
return compress(node, options);
|
|
2414
|
+
}
|
|
2415
|
+
function compress(arr, options, jPath) {
|
|
2416
|
+
let text;
|
|
2417
|
+
const compressedObj = {};
|
|
2418
|
+
for (let i = 0; i < arr.length; i++) {
|
|
2419
|
+
const tagObj = arr[i];
|
|
2420
|
+
const property = propName(tagObj);
|
|
2421
|
+
let newJpath = "";
|
|
2422
|
+
if (jPath === void 0)
|
|
2423
|
+
newJpath = property;
|
|
2424
|
+
else
|
|
2425
|
+
newJpath = jPath + "." + property;
|
|
2426
|
+
if (property === options.textNodeName) {
|
|
2427
|
+
if (text === void 0)
|
|
2428
|
+
text = tagObj[property];
|
|
2429
|
+
else
|
|
2430
|
+
text += "" + tagObj[property];
|
|
2431
|
+
} else if (property === void 0) {
|
|
2432
|
+
continue;
|
|
2433
|
+
} else if (tagObj[property]) {
|
|
2434
|
+
let val = compress(tagObj[property], options, newJpath);
|
|
2435
|
+
const isLeaf = isLeafTag(val, options);
|
|
2436
|
+
if (tagObj[":@"]) {
|
|
2437
|
+
assignAttributes(val, tagObj[":@"], newJpath, options);
|
|
2438
|
+
} else if (Object.keys(val).length === 1 && val[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode) {
|
|
2439
|
+
val = val[options.textNodeName];
|
|
2440
|
+
} else if (Object.keys(val).length === 0) {
|
|
2441
|
+
if (options.alwaysCreateTextNode)
|
|
2442
|
+
val[options.textNodeName] = "";
|
|
2443
|
+
else
|
|
2444
|
+
val = "";
|
|
2445
|
+
}
|
|
2446
|
+
if (compressedObj[property] !== void 0 && compressedObj.hasOwnProperty(property)) {
|
|
2447
|
+
if (!Array.isArray(compressedObj[property])) {
|
|
2448
|
+
compressedObj[property] = [compressedObj[property]];
|
|
2449
|
+
}
|
|
2450
|
+
compressedObj[property].push(val);
|
|
2451
|
+
} else {
|
|
2452
|
+
if (options.isArray(property, newJpath, isLeaf)) {
|
|
2453
|
+
compressedObj[property] = [val];
|
|
2454
|
+
} else {
|
|
2455
|
+
compressedObj[property] = val;
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
if (typeof text === "string") {
|
|
2461
|
+
if (text.length > 0)
|
|
2462
|
+
compressedObj[options.textNodeName] = text;
|
|
2463
|
+
} else if (text !== void 0)
|
|
2464
|
+
compressedObj[options.textNodeName] = text;
|
|
2465
|
+
return compressedObj;
|
|
2466
|
+
}
|
|
2467
|
+
function propName(obj) {
|
|
2468
|
+
const keys = Object.keys(obj);
|
|
2469
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2470
|
+
const key = keys[i];
|
|
2471
|
+
if (key !== ":@")
|
|
2472
|
+
return key;
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
function assignAttributes(obj, attrMap, jpath, options) {
|
|
2476
|
+
if (attrMap) {
|
|
2477
|
+
const keys = Object.keys(attrMap);
|
|
2478
|
+
const len = keys.length;
|
|
2479
|
+
for (let i = 0; i < len; i++) {
|
|
2480
|
+
const atrrName = keys[i];
|
|
2481
|
+
if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
|
|
2482
|
+
obj[atrrName] = [attrMap[atrrName]];
|
|
2483
|
+
} else {
|
|
2484
|
+
obj[atrrName] = attrMap[atrrName];
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
function isLeafTag(obj, options) {
|
|
2490
|
+
const propCount = Object.keys(obj).length;
|
|
2491
|
+
if (propCount === 0 || propCount === 1 && obj[options.textNodeName])
|
|
2492
|
+
return true;
|
|
2493
|
+
return false;
|
|
2494
|
+
}
|
|
2495
|
+
exports.prettify = prettify;
|
|
2496
|
+
}
|
|
2497
|
+
});
|
|
2498
|
+
|
|
2499
|
+
// node_modules/fast-xml-parser/src/xmlparser/XMLParser.js
|
|
2500
|
+
var require_XMLParser = __commonJS({
|
|
2501
|
+
"node_modules/fast-xml-parser/src/xmlparser/XMLParser.js"(exports, module) {
|
|
2502
|
+
var { buildOptions } = require_OptionsBuilder();
|
|
2503
|
+
var OrderedObjParser = require_OrderedObjParser();
|
|
2504
|
+
var { prettify } = require_node2json();
|
|
2505
|
+
var validator = require_validator();
|
|
2506
|
+
var XMLParser = class {
|
|
2507
|
+
constructor(options) {
|
|
2508
|
+
this.externalEntities = {};
|
|
2509
|
+
this.options = buildOptions(options);
|
|
2510
|
+
}
|
|
2511
|
+
parse(xmlData, validationOption) {
|
|
2512
|
+
if (typeof xmlData === "string") {
|
|
2513
|
+
} else if (xmlData.toString) {
|
|
2514
|
+
xmlData = xmlData.toString();
|
|
2515
|
+
} else {
|
|
2516
|
+
throw new Error("XML data is accepted in String or Bytes[] form.");
|
|
2517
|
+
}
|
|
2518
|
+
if (validationOption) {
|
|
2519
|
+
if (validationOption === true)
|
|
2520
|
+
validationOption = {};
|
|
2521
|
+
const result = validator.validate(xmlData, validationOption);
|
|
2522
|
+
if (result !== true) {
|
|
2523
|
+
throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`);
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
const orderedObjParser = new OrderedObjParser(this.options);
|
|
2527
|
+
orderedObjParser.addExternalEntities(this.externalEntities);
|
|
2528
|
+
const orderedResult = orderedObjParser.parseXml(xmlData);
|
|
2529
|
+
if (this.options.preserveOrder || orderedResult === void 0)
|
|
2530
|
+
return orderedResult;
|
|
2531
|
+
else
|
|
2532
|
+
return prettify(orderedResult, this.options);
|
|
2533
|
+
}
|
|
2534
|
+
addEntity(key, value) {
|
|
2535
|
+
if (value.indexOf("&") !== -1) {
|
|
2536
|
+
throw new Error("Entity value can't have '&'");
|
|
2537
|
+
} else if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) {
|
|
2538
|
+
throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");
|
|
2539
|
+
} else if (value === "&") {
|
|
2540
|
+
throw new Error("An entity with value '&' is not permitted");
|
|
2541
|
+
} else {
|
|
2542
|
+
this.externalEntities[key] = value;
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
};
|
|
2546
|
+
module.exports = XMLParser;
|
|
2547
|
+
}
|
|
2548
|
+
});
|
|
2549
|
+
|
|
2550
|
+
// node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js
|
|
2551
|
+
var require_orderedJs2Xml = __commonJS({
|
|
2552
|
+
"node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js"(exports, module) {
|
|
2553
|
+
var EOL = "\n";
|
|
2554
|
+
function toXml(jArray, options) {
|
|
2555
|
+
return arrToStr(jArray, options, "", 0);
|
|
2556
|
+
}
|
|
2557
|
+
function arrToStr(arr, options, jPath, level) {
|
|
2558
|
+
let xmlStr = "";
|
|
2559
|
+
let indentation = "";
|
|
2560
|
+
if (options.format && options.indentBy.length > 0) {
|
|
2561
|
+
indentation = EOL + "" + options.indentBy.repeat(level);
|
|
2562
|
+
}
|
|
2563
|
+
for (let i = 0; i < arr.length; i++) {
|
|
2564
|
+
const tagObj = arr[i];
|
|
2565
|
+
const tagName = propName(tagObj);
|
|
2566
|
+
let newJPath = "";
|
|
2567
|
+
if (jPath.length === 0)
|
|
2568
|
+
newJPath = tagName;
|
|
2569
|
+
else
|
|
2570
|
+
newJPath = `${jPath}.${tagName}`;
|
|
2571
|
+
if (tagName === options.textNodeName) {
|
|
2572
|
+
let tagText = tagObj[tagName];
|
|
2573
|
+
if (!isStopNode(newJPath, options)) {
|
|
2574
|
+
tagText = options.tagValueProcessor(tagName, tagText);
|
|
2575
|
+
tagText = replaceEntitiesValue(tagText, options);
|
|
2576
|
+
}
|
|
2577
|
+
xmlStr += indentation + tagText;
|
|
2578
|
+
continue;
|
|
2579
|
+
} else if (tagName === options.cdataPropName) {
|
|
2580
|
+
xmlStr += indentation + `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
|
|
2581
|
+
continue;
|
|
2582
|
+
} else if (tagName === options.commentPropName) {
|
|
2583
|
+
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
|
|
2584
|
+
continue;
|
|
2585
|
+
} else if (tagName[0] === "?") {
|
|
2586
|
+
const attStr2 = attr_to_str(tagObj[":@"], options);
|
|
2587
|
+
const tempInd = tagName === "?xml" ? "" : indentation;
|
|
2588
|
+
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
2589
|
+
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : "";
|
|
2590
|
+
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr2}?>`;
|
|
2591
|
+
continue;
|
|
2592
|
+
}
|
|
2593
|
+
const attStr = attr_to_str(tagObj[":@"], options);
|
|
2594
|
+
let tagStart = indentation + `<${tagName}${attStr}`;
|
|
2595
|
+
let tagValue = arrToStr(tagObj[tagName], options, newJPath, level + 1);
|
|
2596
|
+
if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
2597
|
+
if (options.suppressUnpairedNode)
|
|
2598
|
+
xmlStr += tagStart + ">";
|
|
2599
|
+
else
|
|
2600
|
+
xmlStr += tagStart + "/>";
|
|
2601
|
+
} else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
|
|
2602
|
+
xmlStr += tagStart + "/>";
|
|
2603
|
+
} else {
|
|
2604
|
+
xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
return xmlStr;
|
|
2608
|
+
}
|
|
2609
|
+
function propName(obj) {
|
|
2610
|
+
const keys = Object.keys(obj);
|
|
2611
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2612
|
+
const key = keys[i];
|
|
2613
|
+
if (key !== ":@")
|
|
2614
|
+
return key;
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
function attr_to_str(attrMap, options) {
|
|
2618
|
+
let attrStr = "";
|
|
2619
|
+
if (attrMap && !options.ignoreAttributes) {
|
|
2620
|
+
for (let attr in attrMap) {
|
|
2621
|
+
let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
|
|
2622
|
+
attrVal = replaceEntitiesValue(attrVal, options);
|
|
2623
|
+
if (attrVal === true && options.suppressBooleanAttributes) {
|
|
2624
|
+
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
2625
|
+
} else {
|
|
2626
|
+
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
return attrStr;
|
|
2631
|
+
}
|
|
2632
|
+
function isStopNode(jPath, options) {
|
|
2633
|
+
jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
|
|
2634
|
+
let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
|
|
2635
|
+
for (let index in options.stopNodes) {
|
|
2636
|
+
if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName)
|
|
2637
|
+
return true;
|
|
2638
|
+
}
|
|
2639
|
+
return false;
|
|
2640
|
+
}
|
|
2641
|
+
function replaceEntitiesValue(textValue, options) {
|
|
2642
|
+
if (textValue && textValue.length > 0 && options.processEntities) {
|
|
2643
|
+
for (let i = 0; i < options.entities.length; i++) {
|
|
2644
|
+
const entity = options.entities[i];
|
|
2645
|
+
textValue = textValue.replace(entity.regex, entity.val);
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
return textValue;
|
|
2649
|
+
}
|
|
2650
|
+
module.exports = toXml;
|
|
2651
|
+
}
|
|
2652
|
+
});
|
|
2653
|
+
|
|
2654
|
+
// node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js
|
|
2655
|
+
var require_json2xml = __commonJS({
|
|
2656
|
+
"node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js"(exports, module) {
|
|
2657
|
+
"use strict";
|
|
2658
|
+
var buildFromOrderedJs = require_orderedJs2Xml();
|
|
2659
|
+
var defaultOptions = {
|
|
2660
|
+
attributeNamePrefix: "@_",
|
|
2661
|
+
attributesGroupName: false,
|
|
2662
|
+
textNodeName: "#text",
|
|
2663
|
+
ignoreAttributes: true,
|
|
2664
|
+
cdataPropName: false,
|
|
2665
|
+
format: false,
|
|
2666
|
+
indentBy: " ",
|
|
2667
|
+
suppressEmptyNode: false,
|
|
2668
|
+
suppressUnpairedNode: true,
|
|
2669
|
+
suppressBooleanAttributes: true,
|
|
2670
|
+
tagValueProcessor: function(key, a) {
|
|
2671
|
+
return a;
|
|
2672
|
+
},
|
|
2673
|
+
attributeValueProcessor: function(attrName, a) {
|
|
2674
|
+
return a;
|
|
2675
|
+
},
|
|
2676
|
+
preserveOrder: false,
|
|
2677
|
+
commentPropName: false,
|
|
2678
|
+
unpairedTags: [],
|
|
2679
|
+
entities: [
|
|
2680
|
+
{ regex: new RegExp("&", "g"), val: "&" },
|
|
2681
|
+
{ regex: new RegExp(">", "g"), val: ">" },
|
|
2682
|
+
{ regex: new RegExp("<", "g"), val: "<" },
|
|
2683
|
+
{ regex: new RegExp("'", "g"), val: "'" },
|
|
2684
|
+
{ regex: new RegExp('"', "g"), val: """ }
|
|
2685
|
+
],
|
|
2686
|
+
processEntities: true,
|
|
2687
|
+
stopNodes: [],
|
|
2688
|
+
transformTagName: false
|
|
2689
|
+
};
|
|
2690
|
+
function Builder(options) {
|
|
2691
|
+
this.options = Object.assign({}, defaultOptions, options);
|
|
2692
|
+
if (this.options.ignoreAttributes || this.options.attributesGroupName) {
|
|
2693
|
+
this.isAttribute = function() {
|
|
2694
|
+
return false;
|
|
2695
|
+
};
|
|
2696
|
+
} else {
|
|
2697
|
+
this.attrPrefixLen = this.options.attributeNamePrefix.length;
|
|
2698
|
+
this.isAttribute = isAttribute;
|
|
2699
|
+
}
|
|
2700
|
+
this.processTextOrObjNode = processTextOrObjNode;
|
|
2701
|
+
if (this.options.format) {
|
|
2702
|
+
this.indentate = indentate;
|
|
2703
|
+
this.tagEndChar = ">\n";
|
|
2704
|
+
this.newLine = "\n";
|
|
2705
|
+
} else {
|
|
2706
|
+
this.indentate = function() {
|
|
2707
|
+
return "";
|
|
2708
|
+
};
|
|
2709
|
+
this.tagEndChar = ">";
|
|
2710
|
+
this.newLine = "";
|
|
2711
|
+
}
|
|
2712
|
+
if (this.options.suppressEmptyNode) {
|
|
2713
|
+
this.buildTextNode = buildEmptyTextNode;
|
|
2714
|
+
this.buildObjNode = buildEmptyObjNode;
|
|
2715
|
+
} else {
|
|
2716
|
+
this.buildTextNode = buildTextValNode;
|
|
2717
|
+
this.buildObjNode = buildObjectNode;
|
|
2718
|
+
}
|
|
2719
|
+
this.buildTextValNode = buildTextValNode;
|
|
2720
|
+
this.buildObjectNode = buildObjectNode;
|
|
2721
|
+
this.replaceEntitiesValue = replaceEntitiesValue;
|
|
2722
|
+
this.buildAttrPairStr = buildAttrPairStr;
|
|
2723
|
+
}
|
|
2724
|
+
Builder.prototype.build = function(jObj) {
|
|
2725
|
+
if (this.options.preserveOrder) {
|
|
2726
|
+
return buildFromOrderedJs(jObj, this.options);
|
|
2727
|
+
} else {
|
|
2728
|
+
if (Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1) {
|
|
2729
|
+
jObj = {
|
|
2730
|
+
[this.options.arrayNodeName]: jObj
|
|
2731
|
+
};
|
|
2732
|
+
}
|
|
2733
|
+
return this.j2x(jObj, 0).val;
|
|
2734
|
+
}
|
|
2735
|
+
};
|
|
2736
|
+
Builder.prototype.j2x = function(jObj, level) {
|
|
2737
|
+
let attrStr = "";
|
|
2738
|
+
let val = "";
|
|
2739
|
+
for (let key in jObj) {
|
|
2740
|
+
if (typeof jObj[key] === "undefined") {
|
|
2741
|
+
} else if (jObj[key] === null) {
|
|
2742
|
+
if (key[0] === "?")
|
|
2743
|
+
val += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
|
|
2744
|
+
else
|
|
2745
|
+
val += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
2746
|
+
} else if (jObj[key] instanceof Date) {
|
|
2747
|
+
val += this.buildTextNode(jObj[key], key, "", level);
|
|
2748
|
+
} else if (typeof jObj[key] !== "object") {
|
|
2749
|
+
const attr = this.isAttribute(key);
|
|
2750
|
+
if (attr) {
|
|
2751
|
+
attrStr += this.buildAttrPairStr(attr, "" + jObj[key]);
|
|
2752
|
+
} else {
|
|
2753
|
+
if (key === this.options.textNodeName) {
|
|
2754
|
+
let newval = this.options.tagValueProcessor(key, "" + jObj[key]);
|
|
2755
|
+
val += this.replaceEntitiesValue(newval);
|
|
2756
|
+
} else {
|
|
2757
|
+
val += this.buildTextNode(jObj[key], key, "", level);
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
} else if (Array.isArray(jObj[key])) {
|
|
2761
|
+
const arrLen = jObj[key].length;
|
|
2762
|
+
for (let j = 0; j < arrLen; j++) {
|
|
2763
|
+
const item = jObj[key][j];
|
|
2764
|
+
if (typeof item === "undefined") {
|
|
2765
|
+
} else if (item === null) {
|
|
2766
|
+
if (key[0] === "?")
|
|
2767
|
+
val += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
|
|
2768
|
+
else
|
|
2769
|
+
val += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
2770
|
+
} else if (typeof item === "object") {
|
|
2771
|
+
val += this.processTextOrObjNode(item, key, level);
|
|
2772
|
+
} else {
|
|
2773
|
+
val += this.buildTextNode(item, key, "", level);
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
} else {
|
|
2777
|
+
if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
|
|
2778
|
+
const Ks = Object.keys(jObj[key]);
|
|
2779
|
+
const L = Ks.length;
|
|
2780
|
+
for (let j = 0; j < L; j++) {
|
|
2781
|
+
attrStr += this.buildAttrPairStr(Ks[j], "" + jObj[key][Ks[j]]);
|
|
2782
|
+
}
|
|
2783
|
+
} else {
|
|
2784
|
+
val += this.processTextOrObjNode(jObj[key], key, level);
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
return { attrStr, val };
|
|
2789
|
+
};
|
|
2790
|
+
function buildAttrPairStr(attrName, val) {
|
|
2791
|
+
val = this.options.attributeValueProcessor(attrName, "" + val);
|
|
2792
|
+
val = this.replaceEntitiesValue(val);
|
|
2793
|
+
if (this.options.suppressBooleanAttributes && val === "true") {
|
|
2794
|
+
return " " + attrName;
|
|
2795
|
+
} else
|
|
2796
|
+
return " " + attrName + '="' + val + '"';
|
|
2797
|
+
}
|
|
2798
|
+
function processTextOrObjNode(object, key, level) {
|
|
2799
|
+
const result = this.j2x(object, level + 1);
|
|
2800
|
+
if (object[this.options.textNodeName] !== void 0 && Object.keys(object).length === 1) {
|
|
2801
|
+
return this.buildTextNode(object[this.options.textNodeName], key, result.attrStr, level);
|
|
2802
|
+
} else {
|
|
2803
|
+
return this.buildObjNode(result.val, key, result.attrStr, level);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
function buildObjectNode(val, key, attrStr, level) {
|
|
2807
|
+
let tagEndExp = "</" + key + this.tagEndChar;
|
|
2808
|
+
let piClosingChar = "";
|
|
2809
|
+
if (key[0] === "?") {
|
|
2810
|
+
piClosingChar = "?";
|
|
2811
|
+
tagEndExp = "";
|
|
2812
|
+
}
|
|
2813
|
+
if (attrStr && val.indexOf("<") === -1) {
|
|
2814
|
+
return this.indentate(level) + "<" + key + attrStr + piClosingChar + ">" + val + tagEndExp;
|
|
2815
|
+
} else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
|
|
2816
|
+
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
2817
|
+
} else {
|
|
2818
|
+
return this.indentate(level) + "<" + key + attrStr + piClosingChar + this.tagEndChar + val + this.indentate(level) + tagEndExp;
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
function buildEmptyObjNode(val, key, attrStr, level) {
|
|
2822
|
+
if (val !== "") {
|
|
2823
|
+
return this.buildObjectNode(val, key, attrStr, level);
|
|
2824
|
+
} else {
|
|
2825
|
+
if (key[0] === "?")
|
|
2826
|
+
return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
|
|
2827
|
+
else
|
|
2828
|
+
return this.indentate(level) + "<" + key + attrStr + "/" + this.tagEndChar;
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
function buildTextValNode(val, key, attrStr, level) {
|
|
2832
|
+
if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
|
|
2833
|
+
return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
|
|
2834
|
+
} else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
|
|
2835
|
+
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
2836
|
+
} else {
|
|
2837
|
+
let textValue = this.options.tagValueProcessor(key, val);
|
|
2838
|
+
textValue = this.replaceEntitiesValue(textValue);
|
|
2839
|
+
if (textValue === "" && this.options.unpairedTags.indexOf(key) !== -1) {
|
|
2840
|
+
if (this.options.suppressUnpairedNode) {
|
|
2841
|
+
return this.indentate(level) + "<" + key + this.tagEndChar;
|
|
2842
|
+
} else {
|
|
2843
|
+
return this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
2844
|
+
}
|
|
2845
|
+
} else {
|
|
2846
|
+
return this.indentate(level) + "<" + key + attrStr + ">" + textValue + "</" + key + this.tagEndChar;
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
function replaceEntitiesValue(textValue) {
|
|
2851
|
+
if (textValue && textValue.length > 0 && this.options.processEntities) {
|
|
2852
|
+
for (let i = 0; i < this.options.entities.length; i++) {
|
|
2853
|
+
const entity = this.options.entities[i];
|
|
2854
|
+
textValue = textValue.replace(entity.regex, entity.val);
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
return textValue;
|
|
2858
|
+
}
|
|
2859
|
+
function buildEmptyTextNode(val, key, attrStr, level) {
|
|
2860
|
+
if (val === "" && this.options.unpairedTags.indexOf(key) !== -1) {
|
|
2861
|
+
if (this.options.suppressUnpairedNode) {
|
|
2862
|
+
return this.indentate(level) + "<" + key + this.tagEndChar;
|
|
2863
|
+
} else {
|
|
2864
|
+
return this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
2865
|
+
}
|
|
2866
|
+
} else if (val !== "") {
|
|
2867
|
+
return this.buildTextValNode(val, key, attrStr, level);
|
|
2868
|
+
} else {
|
|
2869
|
+
if (key[0] === "?")
|
|
2870
|
+
return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
|
|
2871
|
+
else
|
|
2872
|
+
return this.indentate(level) + "<" + key + attrStr + "/" + this.tagEndChar;
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
function indentate(level) {
|
|
2876
|
+
return this.options.indentBy.repeat(level);
|
|
2877
|
+
}
|
|
2878
|
+
function isAttribute(name) {
|
|
2879
|
+
if (name.startsWith(this.options.attributeNamePrefix)) {
|
|
2880
|
+
return name.substr(this.attrPrefixLen);
|
|
2881
|
+
} else {
|
|
2882
|
+
return false;
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
module.exports = Builder;
|
|
2886
|
+
}
|
|
2887
|
+
});
|
|
2888
|
+
|
|
2889
|
+
// node_modules/fast-xml-parser/src/fxp.js
|
|
2890
|
+
var require_fxp = __commonJS({
|
|
2891
|
+
"node_modules/fast-xml-parser/src/fxp.js"(exports, module) {
|
|
2892
|
+
"use strict";
|
|
2893
|
+
var validator = require_validator();
|
|
2894
|
+
var XMLParser = require_XMLParser();
|
|
2895
|
+
var XMLBuilder = require_json2xml();
|
|
2896
|
+
module.exports = {
|
|
2897
|
+
XMLParser,
|
|
2898
|
+
XMLValidator: validator,
|
|
2899
|
+
XMLBuilder
|
|
2900
|
+
};
|
|
2901
|
+
}
|
|
2902
|
+
});
|
|
2903
|
+
|
|
2904
|
+
// src/lib/parse-xml.ts
|
|
2905
|
+
function parseXML(text, options) {
|
|
2906
|
+
const parser = new import_fast_xml_parser.XMLParser({ ...options });
|
|
2907
|
+
const parsedXML = parser.parse(text);
|
|
2908
|
+
return parsedXML;
|
|
2909
|
+
}
|
|
2910
|
+
var import_fast_xml_parser;
|
|
2911
|
+
var init_parse_xml = __esm({
|
|
2912
|
+
"src/lib/parse-xml.ts"() {
|
|
2913
|
+
import_fast_xml_parser = __toModule(require_fxp());
|
|
2914
|
+
}
|
|
2915
|
+
});
|
|
2916
|
+
|
|
2917
|
+
// src/xml-loader.ts
|
|
2918
|
+
function testXMLFile(text) {
|
|
2919
|
+
return text.startsWith("<?xml");
|
|
2920
|
+
}
|
|
2921
|
+
var VERSION, XMLLoader;
|
|
2922
|
+
var init_xml_loader = __esm({
|
|
2923
|
+
"src/xml-loader.ts"() {
|
|
2924
|
+
init_parse_xml();
|
|
2925
|
+
VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2926
|
+
XMLLoader = {
|
|
2927
|
+
name: "XML",
|
|
2928
|
+
id: "xml",
|
|
2929
|
+
module: "xml",
|
|
2930
|
+
version: VERSION,
|
|
2931
|
+
worker: false,
|
|
2932
|
+
extensions: ["xml"],
|
|
2933
|
+
mimeTypes: ["application/xml", "text/xml"],
|
|
2934
|
+
testText: testXMLFile,
|
|
2935
|
+
options: {
|
|
2936
|
+
xml: {}
|
|
2937
|
+
},
|
|
2938
|
+
parse: async (arrayBuffer, options) => parseXML(new TextDecoder().decode(arrayBuffer), options),
|
|
2939
|
+
parseTextSync: (text, options) => parseXML(text, options)
|
|
2940
|
+
};
|
|
2941
|
+
}
|
|
2942
|
+
});
|
|
2943
|
+
|
|
2944
|
+
// src/index.ts
|
|
2945
|
+
var src_exports = {};
|
|
2946
|
+
__export(src_exports, {
|
|
2947
|
+
SAXParser: () => SAXParser,
|
|
2948
|
+
XMLLoader: () => XMLLoader
|
|
2949
|
+
});
|
|
2950
|
+
var init_src = __esm({
|
|
2951
|
+
"src/index.ts"() {
|
|
2952
|
+
init_xml_loader();
|
|
2953
|
+
init_sax();
|
|
2954
|
+
}
|
|
2955
|
+
});
|
|
2956
|
+
|
|
2957
|
+
// src/bundle.ts
|
|
2958
|
+
var require_bundle = __commonJS({
|
|
2959
|
+
"src/bundle.ts"(exports, module) {
|
|
2960
|
+
var moduleExports = (init_src(), src_exports);
|
|
2961
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
2962
|
+
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
2963
|
+
}
|
|
2964
|
+
});
|
|
2965
|
+
require_bundle();
|
|
2966
|
+
})();
|