@cntwg/xml-lib-js 0.0.28 → 0.0.30
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/CHANGELOG.md +18 -0
- package/doc/xmldoc-lib.md +86 -48
- package/lib/xmldoc-lib.js +343 -207
- package/package.json +5 -5
package/lib/xmldoc-lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.092-20240922]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -23,8 +23,8 @@ const {
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @function checkFsError
|
|
26
|
-
* @param {object}
|
|
27
|
-
* @param {Error}
|
|
26
|
+
* @param {object} descr
|
|
27
|
+
* @param {Error} err
|
|
28
28
|
* @returns {object}
|
|
29
29
|
* @inner
|
|
30
30
|
* @description Checs an error code of a fs ops and sets descr info if succeed
|
|
@@ -69,8 +69,8 @@ const XML_TE_NROOT_EMSG = 'root element not found';
|
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* @function readAsTagName
|
|
72
|
-
* @param {any}
|
|
73
|
-
* @
|
|
72
|
+
* @param {any} value
|
|
73
|
+
* @returns {string}
|
|
74
74
|
* @since v0.0.28
|
|
75
75
|
* @description Tries to convert a given value to a valid tag name
|
|
76
76
|
* of an XML-element.
|
|
@@ -92,8 +92,8 @@ function readAsTagName(value) {
|
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* @function readAsAttrName
|
|
95
|
-
* @param {any}
|
|
96
|
-
* @
|
|
95
|
+
* @param {any} value
|
|
96
|
+
* @returns {string}
|
|
97
97
|
* @since v0.0.28
|
|
98
98
|
* @description Tries to convert a given value to a valid name
|
|
99
99
|
* of an XML-attribute.
|
|
@@ -115,8 +115,8 @@ function readAsAttrName(value) {
|
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
117
|
* @function valueToElementID
|
|
118
|
-
* @param {any}
|
|
119
|
-
* @
|
|
118
|
+
* @param {any} value
|
|
119
|
+
* @returns {string}
|
|
120
120
|
* @since v0.0.28
|
|
121
121
|
* @description Tries to convert a given value to a valid identifier
|
|
122
122
|
* suitable as a value for an "ID-attribute" of an XML-element.
|
|
@@ -144,16 +144,18 @@ function valueToElementID(value) {
|
|
|
144
144
|
* @description This class implements an attributes mapper instance
|
|
145
145
|
*/
|
|
146
146
|
class TXmlAttributesMapper {
|
|
147
|
-
|
|
148
|
-
#
|
|
147
|
+
/** @property {?object} */
|
|
148
|
+
#_host;// = null;
|
|
149
|
+
/** @property {?object} */
|
|
150
|
+
#_options;// = null;
|
|
149
151
|
|
|
150
152
|
/**
|
|
151
|
-
* @param {object}
|
|
153
|
+
* @param {object} obj
|
|
152
154
|
* @param {object} [opt]
|
|
153
155
|
* @param {object} [opt.parseOptions]
|
|
154
156
|
* @throws {TypeError}
|
|
155
157
|
*/
|
|
156
|
-
constructor(obj, opt){
|
|
158
|
+
constructor(obj, opt) {
|
|
157
159
|
// init an elements content
|
|
158
160
|
if (!isPlainObject(obj)) throw new TypeError(XML_TE_NOBJ_EMSG);
|
|
159
161
|
this.#_host = obj;
|
|
@@ -178,10 +180,10 @@ class TXmlAttributesMapper {
|
|
|
178
180
|
}
|
|
179
181
|
|
|
180
182
|
/**
|
|
181
|
-
* @property {
|
|
183
|
+
* @property {Array}
|
|
182
184
|
* @readonly
|
|
183
185
|
*/
|
|
184
|
-
get entries(){
|
|
186
|
+
get entries() {
|
|
185
187
|
let items = xObj.getXObjAttributes(
|
|
186
188
|
this.#_host,
|
|
187
189
|
this.#_options.settings.attributesKey,
|
|
@@ -190,11 +192,11 @@ class TXmlAttributesMapper {
|
|
|
190
192
|
}
|
|
191
193
|
|
|
192
194
|
/**
|
|
193
|
-
* @param {
|
|
194
|
-
* @returns {
|
|
195
|
+
* @param {string} name
|
|
196
|
+
* @returns {boolean}
|
|
195
197
|
* @description Checks whether an attribute exists.
|
|
196
198
|
*/
|
|
197
|
-
hasAttribute(name){
|
|
199
|
+
hasAttribute(name) {
|
|
198
200
|
let result = false;
|
|
199
201
|
try {
|
|
200
202
|
result = xObj.checkXObjAttribute(
|
|
@@ -210,11 +212,11 @@ class TXmlAttributesMapper {
|
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
/**
|
|
213
|
-
* @param {
|
|
215
|
+
* @param {string} name
|
|
214
216
|
* @returns {string}
|
|
215
217
|
* @description Returns an attribute value.
|
|
216
218
|
*/
|
|
217
|
-
getAttribute(name){
|
|
219
|
+
getAttribute(name) {
|
|
218
220
|
let result = '';
|
|
219
221
|
try {
|
|
220
222
|
result = xObj.readXObjAttr(
|
|
@@ -230,12 +232,12 @@ class TXmlAttributesMapper {
|
|
|
230
232
|
}
|
|
231
233
|
|
|
232
234
|
/**
|
|
233
|
-
* @param {
|
|
234
|
-
* @param {any}
|
|
235
|
-
* @returns {
|
|
235
|
+
* @param {string} name
|
|
236
|
+
* @param {any} value
|
|
237
|
+
* @returns {boolean}
|
|
236
238
|
* @description Sets an attribute value.
|
|
237
239
|
*/
|
|
238
|
-
setAttribute(name, value){
|
|
240
|
+
setAttribute(name, value) {
|
|
239
241
|
const attrName = readAsAttrName(name);
|
|
240
242
|
let result = false;
|
|
241
243
|
if (attrName !== '') {
|
|
@@ -255,11 +257,11 @@ class TXmlAttributesMapper {
|
|
|
255
257
|
}
|
|
256
258
|
|
|
257
259
|
/**
|
|
258
|
-
* @param {
|
|
259
|
-
* @returns {
|
|
260
|
+
* @param {string} name
|
|
261
|
+
* @returns {boolean}
|
|
260
262
|
* @description Deletes an attribute.
|
|
261
263
|
*/
|
|
262
|
-
delAttribute(name){
|
|
264
|
+
delAttribute(name) {
|
|
263
265
|
let result = false;
|
|
264
266
|
try {
|
|
265
267
|
result = xObj.deleteXObjAttribute(
|
|
@@ -275,10 +277,36 @@ class TXmlAttributesMapper {
|
|
|
275
277
|
}
|
|
276
278
|
|
|
277
279
|
/**
|
|
278
|
-
* @
|
|
280
|
+
* @param {string} name
|
|
281
|
+
* @param {string} value
|
|
282
|
+
* @returns {boolean}
|
|
283
|
+
* @since v0.0.30
|
|
284
|
+
* @description Renames an attribute.
|
|
285
|
+
*/
|
|
286
|
+
renameAttribute(name, value) {
|
|
287
|
+
const newName = readAsAttrName(value);
|
|
288
|
+
let result = false;
|
|
289
|
+
if (newName !== '') {
|
|
290
|
+
try {
|
|
291
|
+
result = xObj.renameXObjAttribute(
|
|
292
|
+
this.#_host,
|
|
293
|
+
name,
|
|
294
|
+
newName,
|
|
295
|
+
this.#_options.settings.attributesKey,
|
|
296
|
+
);
|
|
297
|
+
} catch (err) {
|
|
298
|
+
// // TODO: verify what error is thrown
|
|
299
|
+
result = false;
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* @returns {void}
|
|
279
307
|
* @description Deletes all attributes.
|
|
280
308
|
*/
|
|
281
|
-
clear(){
|
|
309
|
+
clear() {
|
|
282
310
|
xObj.insertXObjElement(
|
|
283
311
|
this.#_host,
|
|
284
312
|
this.#_options.settings.attributesKey,
|
|
@@ -295,20 +323,24 @@ class TXmlAttributesMapper {
|
|
|
295
323
|
* @description This class implements an instance of an element controller
|
|
296
324
|
*/
|
|
297
325
|
class TXmlElementController {
|
|
298
|
-
|
|
299
|
-
#
|
|
300
|
-
|
|
301
|
-
#
|
|
326
|
+
/** @property {?object} */
|
|
327
|
+
#_host;// = null;
|
|
328
|
+
/** @property {?object} */
|
|
329
|
+
#_options;// = null;
|
|
330
|
+
/** @property {?object} */
|
|
331
|
+
#_parseOptions;// = null;
|
|
332
|
+
/** @property {?TXmlAttributesMapper} */
|
|
333
|
+
#_attributes;// = null;
|
|
302
334
|
#_name = null;
|
|
303
335
|
|
|
304
336
|
/**
|
|
305
|
-
* @param {object}
|
|
337
|
+
* @param {object} obj
|
|
306
338
|
* @param {object} [opt]
|
|
307
339
|
* @param {object} [opt.parseOptions]
|
|
308
|
-
* @param {
|
|
340
|
+
* @param {boolean} [opt.proxyModeEnable=false]
|
|
309
341
|
* @throws {TypeError}
|
|
310
342
|
*/
|
|
311
|
-
constructor(obj, opt){
|
|
343
|
+
constructor(obj, opt) {
|
|
312
344
|
// load options
|
|
313
345
|
let _options = isPlainObject(opt) ? opt : {};
|
|
314
346
|
let {
|
|
@@ -317,8 +349,7 @@ class TXmlElementController {
|
|
|
317
349
|
} = _options;
|
|
318
350
|
if (typeof proxyModeEnable !== 'boolean') proxyModeEnable = false;
|
|
319
351
|
// init an element content
|
|
320
|
-
if (
|
|
321
|
-
if (isArray(obj)) return new TXmlElementsListController(obj, opt);
|
|
352
|
+
if (isPlainObject(obj)) {
|
|
322
353
|
// // TODO: split a plain object and class instances
|
|
323
354
|
this.#_host = obj;
|
|
324
355
|
} else {
|
|
@@ -330,20 +361,24 @@ class TXmlElementController {
|
|
|
330
361
|
this.#_host = {};
|
|
331
362
|
};
|
|
332
363
|
// set parser options
|
|
333
|
-
if (!
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
let { settings } = parseOptions;
|
|
337
|
-
if (!isPlainObject(settings)) parseOptions.settings = settings = {};
|
|
338
|
-
let { textKey } = settings;
|
|
339
|
-
if (
|
|
340
|
-
typeof textKey !== 'string'
|
|
341
|
-
|| ((textKey = textKey.trim()) === '')
|
|
342
|
-
) {
|
|
343
|
-
textKey = XML_DEF_PARSE_OPTIONS.textKey;
|
|
364
|
+
if (!(parseOptions instanceof TXmlContentParseOptions)) {
|
|
365
|
+
parseOptions = new TXmlContentParseOptions(parseOptions);
|
|
366
|
+
_options.parseOptions = parseOptions;
|
|
344
367
|
};
|
|
368
|
+
//if (!isPlainObject(parseOptions)) {
|
|
369
|
+
// _options.parseOptions = parseOptions = {};
|
|
370
|
+
//};
|
|
371
|
+
//let { settings } = parseOptions;
|
|
372
|
+
//if (!isPlainObject(settings)) parseOptions.settings = settings = {};
|
|
373
|
+
//let { textKey } = settings;
|
|
374
|
+
//if (
|
|
375
|
+
// typeof textKey !== 'string'
|
|
376
|
+
// || ((textKey = textKey.trim()) === '')
|
|
377
|
+
//) {
|
|
378
|
+
// textKey = XML_DEF_PARSE_OPTIONS.textKey;
|
|
379
|
+
//};
|
|
345
380
|
// save options
|
|
346
|
-
settings.textKey = textKey;
|
|
381
|
+
//settings.textKey = textKey;
|
|
347
382
|
this.#_parseOptions = parseOptions;
|
|
348
383
|
_options.proxyModeEnable = proxyModeEnable;
|
|
349
384
|
this.#_options = _options;
|
|
@@ -355,7 +390,7 @@ class TXmlElementController {
|
|
|
355
390
|
* @property {TXmlAttributesMapper}
|
|
356
391
|
* @readonly
|
|
357
392
|
*/
|
|
358
|
-
get attributes(){
|
|
393
|
+
get attributes() {
|
|
359
394
|
return this.#_attributes;
|
|
360
395
|
}
|
|
361
396
|
|
|
@@ -364,7 +399,7 @@ class TXmlElementController {
|
|
|
364
399
|
* @readonly
|
|
365
400
|
* @experimental
|
|
366
401
|
*/
|
|
367
|
-
get name(){
|
|
402
|
+
get name() {
|
|
368
403
|
let result = '';
|
|
369
404
|
if (this.#_parseOptions.settings.compact) {
|
|
370
405
|
result = xObj.readXObjParam(
|
|
@@ -380,53 +415,69 @@ class TXmlElementController {
|
|
|
380
415
|
/**
|
|
381
416
|
* @property {string}
|
|
382
417
|
*/
|
|
383
|
-
get textValue(){
|
|
418
|
+
get textValue() {
|
|
384
419
|
return xObj.readXObjParam(this.#_host, this.#_parseOptions.settings.textKey);
|
|
385
420
|
}
|
|
386
421
|
|
|
387
|
-
set textValue(value){
|
|
422
|
+
set textValue(value) {
|
|
388
423
|
xObj.writeXObjParam(this.#_host, value, this.#_parseOptions.settings.textKey);
|
|
389
424
|
}
|
|
390
425
|
|
|
391
426
|
/**
|
|
392
|
-
* @param {
|
|
393
|
-
* @returns {
|
|
427
|
+
* @param {string} name
|
|
428
|
+
* @returns {boolean}
|
|
394
429
|
* @description Checks whether an attribute exists.
|
|
395
430
|
*/
|
|
396
|
-
hasAttribute(name){
|
|
431
|
+
hasAttribute(name) {
|
|
397
432
|
return this.#_attributes.hasAttribute(name);
|
|
398
433
|
}
|
|
399
434
|
|
|
400
435
|
/**
|
|
401
|
-
* @param {
|
|
436
|
+
* @param {string} name
|
|
402
437
|
* @returns {string}
|
|
403
438
|
* @description Returns an attribute value.
|
|
404
439
|
*/
|
|
405
|
-
getAttribute(name){
|
|
440
|
+
getAttribute(name) {
|
|
406
441
|
return this.#_attributes.getAttribute(name);
|
|
407
442
|
}
|
|
408
443
|
|
|
409
444
|
/**
|
|
445
|
+
* @param {string} name
|
|
446
|
+
* @param {any} value
|
|
447
|
+
* @returns {boolean}
|
|
448
|
+
* @description Sets an attribute value.
|
|
410
449
|
* @see TXmlAttributesMapper.setAttribute
|
|
411
450
|
*/
|
|
412
|
-
setAttribute(...args){
|
|
451
|
+
setAttribute(...args) {
|
|
413
452
|
return this.#_attributes.setAttribute(...args);
|
|
414
453
|
}
|
|
415
454
|
|
|
416
455
|
/**
|
|
417
|
-
* @param {
|
|
418
|
-
* @returns {
|
|
456
|
+
* @param {string} name
|
|
457
|
+
* @returns {boolean}
|
|
419
458
|
* @description Deletes an attribute.
|
|
420
459
|
*/
|
|
421
|
-
delAttribute(name){
|
|
460
|
+
delAttribute(name) {
|
|
422
461
|
return this.#_attributes.delAttribute(name);
|
|
423
462
|
}
|
|
424
463
|
|
|
425
464
|
/**
|
|
426
|
-
* @
|
|
465
|
+
* @param {string} name
|
|
466
|
+
* @param {string} value
|
|
467
|
+
* @returns {boolean}
|
|
468
|
+
* @since v0.0.30
|
|
469
|
+
* @description Renames an attribute.
|
|
470
|
+
* @see TXmlAttributesMapper.renameAttribute
|
|
471
|
+
*/
|
|
472
|
+
renameAttribute(...args) {
|
|
473
|
+
return this.#_attributes.renameAttribute(...args);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* @returns {string[]}
|
|
427
478
|
* @description Returns a text value in format of a `[ <lang>, <text> ]` pair.
|
|
428
479
|
*/
|
|
429
|
-
getTextValue(){
|
|
480
|
+
getTextValue() {
|
|
430
481
|
return [
|
|
431
482
|
this.#_attributes.getAttribute(XML_LANG_ATTR_TNAME),
|
|
432
483
|
this.textValue,
|
|
@@ -434,11 +485,11 @@ class TXmlElementController {
|
|
|
434
485
|
}
|
|
435
486
|
|
|
436
487
|
/**
|
|
437
|
-
* @param {(string|
|
|
438
|
-
* @returns {
|
|
488
|
+
* @param {(string|string[])} value
|
|
489
|
+
* @returns {boolean}
|
|
439
490
|
* @description Sets a text value.
|
|
440
491
|
*/
|
|
441
|
-
setTextValue(value){
|
|
492
|
+
setTextValue(value) {
|
|
442
493
|
const _value = valueToEntry(value);
|
|
443
494
|
if (_value !== null) {
|
|
444
495
|
const [ lang, param ] = _value;
|
|
@@ -463,8 +514,8 @@ class TXmlElementController {
|
|
|
463
514
|
}
|
|
464
515
|
|
|
465
516
|
/**
|
|
466
|
-
* @param {
|
|
467
|
-
* @returns {
|
|
517
|
+
* @param {string} name
|
|
518
|
+
* @returns {boolean}
|
|
468
519
|
* @description Checks whether an element has a child element.
|
|
469
520
|
*/
|
|
470
521
|
hasChild(name) {
|
|
@@ -482,36 +533,32 @@ class TXmlElementController {
|
|
|
482
533
|
}
|
|
483
534
|
|
|
484
535
|
/**
|
|
485
|
-
* @param {
|
|
536
|
+
* @param {string} name
|
|
486
537
|
* @returns {(null|TXmlElementController|TXmlElementsListController)}
|
|
487
538
|
* @description Returns a child element.
|
|
488
539
|
*/
|
|
489
540
|
getChild(name) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
result =
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
} else {
|
|
541
|
+
const _name = xObj.evalXObjEName(name);
|
|
542
|
+
let result = null;
|
|
543
|
+
if (_name !== null) {
|
|
544
|
+
try {
|
|
545
|
+
const item = xObj.getXObjElement(this.#_host, _name);
|
|
546
|
+
result = TXmlElementController.create(item, this.#_options);
|
|
547
|
+
} catch (err) {
|
|
548
|
+
// // TODO: [?] verify what error is thrown
|
|
499
549
|
result = null;
|
|
500
550
|
};
|
|
501
|
-
} catch (err) {
|
|
502
|
-
// // TODO: [?] verify what error is thrown
|
|
503
|
-
result = null;
|
|
504
551
|
};
|
|
505
552
|
return result;
|
|
506
553
|
}
|
|
507
554
|
|
|
508
555
|
/**
|
|
509
|
-
* @param {
|
|
556
|
+
* @param {string} name
|
|
510
557
|
* @returns {object}
|
|
511
558
|
* @protected
|
|
512
559
|
* @description Returns a child element.
|
|
513
560
|
*/
|
|
514
|
-
_getChildRaw(name){
|
|
561
|
+
_getChildRaw(name) {
|
|
515
562
|
//console.log('CHECK: TXmlElementController._getChildRaw() => was called...');
|
|
516
563
|
//console.log('CHECK: TXmlElementController._getChildRaw() => _host => '+JSON.stringify(this.#_host, null, 2));
|
|
517
564
|
let item = xObj.getXObjElement(this.#_host, name);
|
|
@@ -524,22 +571,25 @@ class TXmlElementController {
|
|
|
524
571
|
}
|
|
525
572
|
|
|
526
573
|
/**
|
|
527
|
-
* @
|
|
574
|
+
* @param {string} name
|
|
575
|
+
* @param {object} obj
|
|
576
|
+
* @returns {boolean}
|
|
528
577
|
* @protected
|
|
529
578
|
* @description Sets a child element.
|
|
579
|
+
* @see TXmlElementController.__setChildRaw
|
|
530
580
|
*/
|
|
531
|
-
_setChildRaw(...args){
|
|
581
|
+
_setChildRaw(...args) {
|
|
532
582
|
//console.log('CHECK: TXmlElementController._setChildRaw() => was called...');
|
|
533
583
|
return TXmlElementController.__setChildRaw(this, ...args);
|
|
534
584
|
}
|
|
535
585
|
|
|
536
586
|
/**
|
|
537
|
-
* @param {
|
|
587
|
+
* @param {string} name
|
|
538
588
|
* @returns {?object}
|
|
539
589
|
* @protected
|
|
540
590
|
* @description Adds a new child element.
|
|
541
591
|
*/
|
|
542
|
-
_addChildRaw(name)
|
|
592
|
+
_addChildRaw(name) {
|
|
543
593
|
//console.log('CHECK: TXmlElementController._addChild() => was called...');
|
|
544
594
|
//console.log('CHECK: TXmlElementController._addChildRaw() => _host => '+JSON.stringify(this.#_host, null, 2));
|
|
545
595
|
let result = xObj.addXObjElement(this.#_host, name);
|
|
@@ -552,7 +602,7 @@ class TXmlElementController {
|
|
|
552
602
|
}
|
|
553
603
|
|
|
554
604
|
/**
|
|
555
|
-
* @param {
|
|
605
|
+
* @param {string} name
|
|
556
606
|
* @returns {?TXmlElementController}
|
|
557
607
|
* @description Adds a new child element.
|
|
558
608
|
*/
|
|
@@ -572,8 +622,8 @@ class TXmlElementController {
|
|
|
572
622
|
}
|
|
573
623
|
|
|
574
624
|
/**
|
|
575
|
-
* @param {
|
|
576
|
-
* @returns {
|
|
625
|
+
* @param {string} name
|
|
626
|
+
* @returns {boolean}
|
|
577
627
|
* @description Deletes a child element.
|
|
578
628
|
*/
|
|
579
629
|
delChild(name) {
|
|
@@ -605,34 +655,83 @@ class TXmlElementController {
|
|
|
605
655
|
}
|
|
606
656
|
|
|
607
657
|
/**
|
|
608
|
-
* @returns {
|
|
658
|
+
* @returns {void}
|
|
609
659
|
* @description Deletes all child elements and attributes.
|
|
610
660
|
*/
|
|
611
|
-
clear(){
|
|
661
|
+
clear() {
|
|
612
662
|
TXmlElementController.clear(this);
|
|
613
663
|
}
|
|
614
664
|
|
|
615
665
|
/**
|
|
616
|
-
* @param {
|
|
666
|
+
* @param {string} loadFromXMLString
|
|
667
|
+
* @returns {boolean}
|
|
668
|
+
* @throws {Error}
|
|
669
|
+
* @experimental
|
|
670
|
+
* @description Loads a element content from a string.
|
|
671
|
+
*/
|
|
672
|
+
loadFromXMLString(xmlString) {
|
|
673
|
+
let result = false;
|
|
674
|
+
if (typeof xmlString === 'string' && xmlString !== '') {
|
|
675
|
+
const _options = this.#_options;
|
|
676
|
+
let {
|
|
677
|
+
proxyModeEnable,
|
|
678
|
+
parseOptions,
|
|
679
|
+
} = _options;
|
|
680
|
+
parseOptions = parseOptions.xml2js;
|
|
681
|
+
parseOptions.ignoreDocType = true;
|
|
682
|
+
parseOptions.ignoreDeclaration = true;
|
|
683
|
+
try {
|
|
684
|
+
let obj = xmlParser.xml2js(xmlString, parseOptions);
|
|
685
|
+
if (isPlainObject(obj)) {
|
|
686
|
+
let list = Object.entries(obj);
|
|
687
|
+
let item = list[0];
|
|
688
|
+
obj = item[1];
|
|
689
|
+
if (isPlainObject(obj)) {
|
|
690
|
+
if (proxyModeEnable) {
|
|
691
|
+
let list = Object.entries(obj);
|
|
692
|
+
const target = this.#_host;
|
|
693
|
+
this.clear();
|
|
694
|
+
list.forEach((entry) => {
|
|
695
|
+
const [key, value] = entry;
|
|
696
|
+
target[key] = value;
|
|
697
|
+
});
|
|
698
|
+
} else {
|
|
699
|
+
this.#_host = obj;
|
|
700
|
+
};
|
|
701
|
+
this.#_attributes = new TXmlAttributesMapper(obj, _options);
|
|
702
|
+
result = true;
|
|
703
|
+
};
|
|
704
|
+
};
|
|
705
|
+
} catch (err) {
|
|
706
|
+
//console.log('CHECK: TXmlContentContainer.loadFromXMLString() => Error => '+err);
|
|
707
|
+
//console.log('CHECK: TXmlContentContainer.loadFromXMLString() => Error => '+err.code);
|
|
708
|
+
throw err;
|
|
709
|
+
};
|
|
710
|
+
};
|
|
711
|
+
return result;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* @param {object} item
|
|
617
716
|
* @returns {?object}
|
|
618
717
|
* @protected
|
|
619
718
|
* @static
|
|
620
719
|
* @description Tries to unwraps a given object.
|
|
621
720
|
*/
|
|
622
|
-
static __unwrap(item){
|
|
721
|
+
static __unwrap(item) {
|
|
623
722
|
return (item instanceof TXmlElementController) ? item.#_host : null;
|
|
624
723
|
}
|
|
625
724
|
|
|
626
725
|
/**
|
|
627
|
-
* @param {TXmlElementController}
|
|
628
|
-
* @param {
|
|
629
|
-
* @param {object}
|
|
630
|
-
* @returns {
|
|
726
|
+
* @param {TXmlElementController} node
|
|
727
|
+
* @param {string} name
|
|
728
|
+
* @param {object} obj
|
|
729
|
+
* @returns {boolean}
|
|
631
730
|
* @protected
|
|
632
731
|
* @static
|
|
633
732
|
* @description Sets a child element.
|
|
634
733
|
*/
|
|
635
|
-
static __setChildRaw(node, name, obj){
|
|
734
|
+
static __setChildRaw(node, name, obj) {
|
|
636
735
|
//console.log('CHECK: TXmlElementController.__setChildRaw() => was called...');
|
|
637
736
|
let isSUCCEED = false;
|
|
638
737
|
if (node instanceof TXmlElementController) {
|
|
@@ -655,12 +754,12 @@ class TXmlElementController {
|
|
|
655
754
|
}
|
|
656
755
|
|
|
657
756
|
/**
|
|
658
|
-
* @param {object}
|
|
659
|
-
* @returns {
|
|
757
|
+
* @param {object} obj
|
|
758
|
+
* @returns {void}
|
|
660
759
|
* @static
|
|
661
760
|
* @description Tries to clean a given object.
|
|
662
761
|
*/
|
|
663
|
-
static clear(obj){
|
|
762
|
+
static clear(obj) {
|
|
664
763
|
let item = TXmlElementController.__unwrap(obj);
|
|
665
764
|
if (item) {
|
|
666
765
|
for (let prop in item) {
|
|
@@ -670,25 +769,51 @@ class TXmlElementController {
|
|
|
670
769
|
};
|
|
671
770
|
}
|
|
672
771
|
|
|
772
|
+
/**
|
|
773
|
+
* @param {object} obj
|
|
774
|
+
* @param {object} [opt]
|
|
775
|
+
* @returns {(null|TXmlElementController|TXmlElementsListController)}
|
|
776
|
+
* @static
|
|
777
|
+
* @description Creates new controller element.
|
|
778
|
+
*/
|
|
779
|
+
static create(obj, opt) {
|
|
780
|
+
let result = null;
|
|
781
|
+
try {
|
|
782
|
+
if (isObject(obj)) {
|
|
783
|
+
if (isArray(obj)) {
|
|
784
|
+
result = new TXmlElementsListController(obj, opt);
|
|
785
|
+
} else {
|
|
786
|
+
// // TODO: [?] check what kind of object passed in
|
|
787
|
+
result = new TXmlElementController(obj, opt);
|
|
788
|
+
};
|
|
789
|
+
};
|
|
790
|
+
} catch (err) {
|
|
791
|
+
result = null;
|
|
792
|
+
};
|
|
793
|
+
return result;
|
|
794
|
+
}
|
|
795
|
+
|
|
673
796
|
};
|
|
674
797
|
|
|
675
798
|
/**
|
|
676
799
|
* @description This class implements an instance of a list controller
|
|
677
800
|
*/
|
|
678
801
|
class TXmlElementsListController {
|
|
679
|
-
|
|
680
|
-
#
|
|
802
|
+
/** @property {?Array} */
|
|
803
|
+
#_host;// = null;
|
|
804
|
+
/** @property {?object} */
|
|
805
|
+
#_options;// = null;
|
|
681
806
|
#_count = null;
|
|
682
807
|
|
|
683
808
|
/**
|
|
684
|
-
* @param {
|
|
809
|
+
* @param {Array} obj
|
|
685
810
|
* @param {object} [opt]
|
|
686
811
|
* @param {object} [opt.parseOptions]
|
|
687
|
-
* @param {
|
|
688
|
-
* @param {
|
|
812
|
+
* @param {boolean} [opt.proxyModeEnable=false]
|
|
813
|
+
* @param {boolean} [opt.isNullItemsAllowed=false] - <reserved>
|
|
689
814
|
* @throws {TypeError}
|
|
690
815
|
*/
|
|
691
|
-
constructor(obj, opt){
|
|
816
|
+
constructor(obj, opt) {
|
|
692
817
|
// load options
|
|
693
818
|
let _options = isPlainObject(opt) ? opt : {};
|
|
694
819
|
let {
|
|
@@ -727,7 +852,7 @@ class TXmlElementsListController {
|
|
|
727
852
|
* @property {number}
|
|
728
853
|
* @readonly
|
|
729
854
|
*/
|
|
730
|
-
get count(){
|
|
855
|
+
get count() {
|
|
731
856
|
return this.#_host.length;
|
|
732
857
|
}
|
|
733
858
|
|
|
@@ -735,67 +860,67 @@ class TXmlElementsListController {
|
|
|
735
860
|
* @property {number}
|
|
736
861
|
* @readonly
|
|
737
862
|
*/
|
|
738
|
-
get size(){
|
|
863
|
+
get size() {
|
|
739
864
|
return this.#_host.length;
|
|
740
865
|
}
|
|
741
866
|
|
|
742
867
|
/**
|
|
743
|
-
* @property {
|
|
868
|
+
* @property {number}
|
|
744
869
|
* @readonly
|
|
745
870
|
*/
|
|
746
|
-
get maxIndex(){
|
|
871
|
+
get maxIndex() {
|
|
747
872
|
return this.#_host.length - 1;
|
|
748
873
|
}
|
|
749
874
|
|
|
750
875
|
/**
|
|
751
|
-
* @property {
|
|
876
|
+
* @property {boolean}
|
|
752
877
|
* @readonly
|
|
753
878
|
*/
|
|
754
|
-
get isNullItemsAllowed(){
|
|
879
|
+
get isNullItemsAllowed() {
|
|
755
880
|
return readAsBool(this.#_options.isNullItemsAllowed);
|
|
756
881
|
}
|
|
757
882
|
|
|
758
883
|
/**
|
|
759
|
-
* @returns {
|
|
884
|
+
* @returns {void}
|
|
760
885
|
* @description Deletes all child elements and attributes.
|
|
761
886
|
*/
|
|
762
|
-
clear(){
|
|
887
|
+
clear() {
|
|
763
888
|
this.#_host.length = 0;
|
|
764
889
|
}
|
|
765
890
|
|
|
766
891
|
/**
|
|
767
|
-
* @returns {
|
|
892
|
+
* @returns {boolean}
|
|
768
893
|
* @description Checks whether an instance holds none element.
|
|
769
894
|
*/
|
|
770
|
-
isEmpty(){
|
|
895
|
+
isEmpty() {
|
|
771
896
|
return this.count === 0;
|
|
772
897
|
}
|
|
773
898
|
|
|
774
899
|
/**
|
|
775
|
-
* @returns {
|
|
900
|
+
* @returns {boolean}
|
|
776
901
|
* @description Checks whether an instance holds at least one element.
|
|
777
902
|
*/
|
|
778
|
-
isNotEmpty(){
|
|
903
|
+
isNotEmpty() {
|
|
779
904
|
return this.count > 0;
|
|
780
905
|
}
|
|
781
906
|
|
|
782
907
|
/**
|
|
783
|
-
* @param {any}
|
|
784
|
-
* @returns {
|
|
908
|
+
* @param {any} value
|
|
909
|
+
* @returns {boolean}
|
|
785
910
|
* @description Checks whether a given value is a valid index value
|
|
786
911
|
* and it is not exceeds an index range within the instance.
|
|
787
912
|
*/
|
|
788
|
-
chkIndex(value){
|
|
913
|
+
chkIndex(value) {
|
|
789
914
|
const index = valueToIndex(value);
|
|
790
915
|
return index !== -1 && index < this.size;
|
|
791
916
|
}
|
|
792
917
|
|
|
793
918
|
/**
|
|
794
|
-
* @param {any}
|
|
795
|
-
* @returns {
|
|
919
|
+
* @param {any} obj
|
|
920
|
+
* @returns {boolean}
|
|
796
921
|
* @description Checks whether or not a given element is valid.
|
|
797
922
|
*/
|
|
798
|
-
isValidItem(obj){
|
|
923
|
+
isValidItem(obj) {
|
|
799
924
|
return (
|
|
800
925
|
(this.#_options.isNullItemsAllowed && obj === null)
|
|
801
926
|
|| isPlainObject(obj)
|
|
@@ -803,22 +928,22 @@ class TXmlElementsListController {
|
|
|
803
928
|
}
|
|
804
929
|
|
|
805
930
|
/**
|
|
806
|
-
* @param {index
|
|
931
|
+
* @param {number} index
|
|
807
932
|
* @returns {?object}
|
|
808
933
|
* @protected
|
|
809
934
|
* @description Returns an element.
|
|
810
935
|
*/
|
|
811
|
-
_getItemRaw(index){
|
|
936
|
+
_getItemRaw(index) {
|
|
812
937
|
let item = this.#_host[valueToIndex(index)];
|
|
813
938
|
return item !== undefined ? item : null;
|
|
814
939
|
}
|
|
815
940
|
|
|
816
941
|
/**
|
|
817
|
-
* @param {index
|
|
942
|
+
* @param {number} index
|
|
818
943
|
* @returns {?TXmlElementController}
|
|
819
944
|
* @description Returns an element.
|
|
820
945
|
*/
|
|
821
|
-
getItem(index){
|
|
946
|
+
getItem(index) {
|
|
822
947
|
let item = this.#_host[valueToIndex(index)];
|
|
823
948
|
// wrap item in container
|
|
824
949
|
return (
|
|
@@ -829,12 +954,12 @@ class TXmlElementsListController {
|
|
|
829
954
|
}
|
|
830
955
|
|
|
831
956
|
/**
|
|
832
|
-
* @param {any}
|
|
833
|
-
* @returns {
|
|
957
|
+
* @param {any} item
|
|
958
|
+
* @returns {number}
|
|
834
959
|
* @protected
|
|
835
960
|
* @description Adds a new element.
|
|
836
961
|
*/
|
|
837
|
-
_addItemRaw(item){
|
|
962
|
+
_addItemRaw(item) {
|
|
838
963
|
let index = -1;
|
|
839
964
|
if (this.isValidItem(item)) {
|
|
840
965
|
index = this.size;
|
|
@@ -844,11 +969,11 @@ class TXmlElementsListController {
|
|
|
844
969
|
}
|
|
845
970
|
|
|
846
971
|
/**
|
|
847
|
-
* @param {any}
|
|
848
|
-
* @returns {
|
|
972
|
+
* @param {any} item
|
|
973
|
+
* @returns {number}
|
|
849
974
|
* @description Adds a new element.
|
|
850
975
|
*/
|
|
851
|
-
addItem(item){
|
|
976
|
+
addItem(item) {
|
|
852
977
|
// unwrap item from container
|
|
853
978
|
if (item instanceof TXmlElementController) {
|
|
854
979
|
item = TXmlElementController.__unwrap(item);
|
|
@@ -857,25 +982,25 @@ class TXmlElementsListController {
|
|
|
857
982
|
}
|
|
858
983
|
|
|
859
984
|
/**
|
|
860
|
-
* @param {index
|
|
861
|
-
* @param {any}
|
|
862
|
-
* @returns {
|
|
985
|
+
* @param {number} index
|
|
986
|
+
* @param {any} item
|
|
987
|
+
* @returns {boolean}
|
|
863
988
|
* @protected
|
|
864
989
|
* @description Sets a new element.
|
|
865
990
|
*/
|
|
866
|
-
_setItemRaw(index, item){
|
|
991
|
+
_setItemRaw(index, item) {
|
|
867
992
|
let isSUCCEED = this.chkIndex(index) && this.isValidItem(item);
|
|
868
993
|
if (isSUCCEED) this.#_host[Number(index)] = item; // // TODO: correct count
|
|
869
994
|
return isSUCCEED;
|
|
870
995
|
}
|
|
871
996
|
|
|
872
997
|
/**
|
|
873
|
-
* @param {index
|
|
874
|
-
* @param {any}
|
|
875
|
-
* @returns {
|
|
998
|
+
* @param {string} index
|
|
999
|
+
* @param {any} item
|
|
1000
|
+
* @returns {boolean}
|
|
876
1001
|
* @description Sets a new element.
|
|
877
1002
|
*/
|
|
878
|
-
setItem(index, item){
|
|
1003
|
+
setItem(index, item) {
|
|
879
1004
|
// unwrap item from container
|
|
880
1005
|
if (item instanceof TXmlElementController) {
|
|
881
1006
|
item = TXmlElementController.__unwrap(item);
|
|
@@ -884,13 +1009,13 @@ class TXmlElementsListController {
|
|
|
884
1009
|
}
|
|
885
1010
|
|
|
886
1011
|
/**
|
|
887
|
-
* @param {index
|
|
888
|
-
* @param {any}
|
|
889
|
-
* @returns {
|
|
1012
|
+
* @param {number} index
|
|
1013
|
+
* @param {any} item
|
|
1014
|
+
* @returns {boolean}
|
|
890
1015
|
* @protected
|
|
891
1016
|
* @description Insertes a new element.
|
|
892
1017
|
*/
|
|
893
|
-
_insItemRaw(index, item){
|
|
1018
|
+
_insItemRaw(index, item) {
|
|
894
1019
|
index = valueToIndex(index);
|
|
895
1020
|
let size = this.size;
|
|
896
1021
|
let isSUCCEED = (
|
|
@@ -911,12 +1036,12 @@ class TXmlElementsListController {
|
|
|
911
1036
|
}
|
|
912
1037
|
|
|
913
1038
|
/**
|
|
914
|
-
* @param {index
|
|
915
|
-
* @param {any}
|
|
916
|
-
* @returns {
|
|
1039
|
+
* @param {number} index
|
|
1040
|
+
* @param {any} item
|
|
1041
|
+
* @returns {boolean}
|
|
917
1042
|
* @description Insertes a new element.
|
|
918
1043
|
*/
|
|
919
|
-
insItem(index, item){
|
|
1044
|
+
insItem(index, item) {
|
|
920
1045
|
// unwrap item from container
|
|
921
1046
|
if (item instanceof TXmlElementController) {
|
|
922
1047
|
item = TXmlElementController.__unwrap(item);
|
|
@@ -925,11 +1050,11 @@ class TXmlElementsListController {
|
|
|
925
1050
|
}
|
|
926
1051
|
|
|
927
1052
|
/**
|
|
928
|
-
* @param {index
|
|
929
|
-
* @returns {
|
|
1053
|
+
* @param {number} index
|
|
1054
|
+
* @returns {boolean}
|
|
930
1055
|
* @description Deletes an element.
|
|
931
1056
|
*/
|
|
932
|
-
delItem(value){
|
|
1057
|
+
delItem(value) {
|
|
933
1058
|
let isSUCCEED = this.chkIndex(value);
|
|
934
1059
|
if (isSUCCEED) {
|
|
935
1060
|
let index = Number(value);
|
|
@@ -949,13 +1074,13 @@ class TXmlElementsListController {
|
|
|
949
1074
|
}
|
|
950
1075
|
|
|
951
1076
|
/**
|
|
952
|
-
* @param {any}
|
|
1077
|
+
* @param {any} items
|
|
953
1078
|
* @param {object} [opt]
|
|
954
|
-
* @param {
|
|
1079
|
+
* @param {boolean} [opt.useClear=true]
|
|
955
1080
|
* @returns {number}
|
|
956
1081
|
* @description Loads a list of an elements.
|
|
957
1082
|
*/
|
|
958
|
-
loadItems(items, opt){
|
|
1083
|
+
loadItems(items, opt) {
|
|
959
1084
|
const _options = isPlainObject(opt) ? opt : {};
|
|
960
1085
|
let {
|
|
961
1086
|
useClear,
|
|
@@ -974,17 +1099,20 @@ class TXmlElementsListController {
|
|
|
974
1099
|
* that managea content of a document declaration
|
|
975
1100
|
*/
|
|
976
1101
|
class TXmlContentDeclaration {
|
|
977
|
-
|
|
978
|
-
#
|
|
979
|
-
|
|
1102
|
+
/** @property {?object} */
|
|
1103
|
+
#_host;// = null;
|
|
1104
|
+
/** @property {?object} */
|
|
1105
|
+
#_options;// = null;
|
|
1106
|
+
/** @property {?TXmlElementController} */
|
|
1107
|
+
#_ctrls;// = null;
|
|
980
1108
|
|
|
981
1109
|
/**
|
|
982
|
-
* @param {object}
|
|
1110
|
+
* @param {object} obj
|
|
983
1111
|
* @param {object} [opt]
|
|
984
1112
|
* @param {object} [opt.parseOptions]
|
|
985
1113
|
* @throws {TypeError}
|
|
986
1114
|
*/
|
|
987
|
-
constructor(obj, opt){
|
|
1115
|
+
constructor(obj, opt) {
|
|
988
1116
|
// check <obj>-param
|
|
989
1117
|
if (!isPlainObject(obj)) {
|
|
990
1118
|
throw new TypeError(`TXmlContentDeclaration : ${XML_TE_NOBJ_EMSG}`);
|
|
@@ -1017,30 +1145,30 @@ class TXmlContentDeclaration {
|
|
|
1017
1145
|
/**
|
|
1018
1146
|
* @property {string}
|
|
1019
1147
|
*/
|
|
1020
|
-
get version(){
|
|
1148
|
+
get version() {
|
|
1021
1149
|
return this.#_ctrls.getAttribute('version');
|
|
1022
1150
|
}
|
|
1023
1151
|
|
|
1024
|
-
set version(value){
|
|
1152
|
+
set version(value) {
|
|
1025
1153
|
this.#_ctrls.setAttribute('version', value);
|
|
1026
1154
|
}
|
|
1027
1155
|
|
|
1028
1156
|
/**
|
|
1029
1157
|
* @property {string}
|
|
1030
1158
|
*/
|
|
1031
|
-
get encoding(){
|
|
1159
|
+
get encoding() {
|
|
1032
1160
|
return this.#_ctrls.getAttribute('encoding');
|
|
1033
1161
|
}
|
|
1034
1162
|
|
|
1035
|
-
set encoding(value){
|
|
1163
|
+
set encoding(value) {
|
|
1036
1164
|
this.#_ctrls.setAttribute('encoding', value);
|
|
1037
1165
|
}
|
|
1038
1166
|
|
|
1039
1167
|
/**
|
|
1040
|
-
* @returns {
|
|
1168
|
+
* @returns {boolean}
|
|
1041
1169
|
* @description Initializes an instance content.
|
|
1042
1170
|
*/
|
|
1043
|
-
init(){
|
|
1171
|
+
init() {
|
|
1044
1172
|
const _options = this.#_options;
|
|
1045
1173
|
this.#_ctrls = new TXmlElementController(
|
|
1046
1174
|
xObj.insertXObjElement(
|
|
@@ -1061,18 +1189,20 @@ class TXmlContentDeclaration {
|
|
|
1061
1189
|
* @description This class implements an instance of a root element
|
|
1062
1190
|
*/
|
|
1063
1191
|
class TXmlContentRootElement extends TXmlElementController {
|
|
1064
|
-
|
|
1065
|
-
#
|
|
1192
|
+
/** @property {?object} */
|
|
1193
|
+
#_content;// = null;
|
|
1194
|
+
/** @property {?object} */
|
|
1195
|
+
#_options;// = null;
|
|
1066
1196
|
|
|
1067
1197
|
/**
|
|
1068
|
-
* @param {object}
|
|
1198
|
+
* @param {object} obj
|
|
1069
1199
|
* @param {object} [opt]
|
|
1070
1200
|
* @param {object} [opt.parseOptions]
|
|
1071
|
-
* @param {
|
|
1072
|
-
* @param {
|
|
1201
|
+
* @param {string} [opt.rootETagName='']
|
|
1202
|
+
* @param {boolean} [opt.autoBindRoot=true]
|
|
1073
1203
|
* @throws {TypeError}
|
|
1074
1204
|
*/
|
|
1075
|
-
constructor(obj, opt){
|
|
1205
|
+
constructor(obj, opt) {
|
|
1076
1206
|
// check <obj>-param
|
|
1077
1207
|
if (!isPlainObject(obj)) {
|
|
1078
1208
|
throw new TypeError(`TXmlContentRootElement : ${XML_TE_NOBJ_EMSG}`);
|
|
@@ -1160,11 +1290,11 @@ class TXmlContentRootElement extends TXmlElementController {
|
|
|
1160
1290
|
/**
|
|
1161
1291
|
* @property {string}
|
|
1162
1292
|
*/
|
|
1163
|
-
get tagName(){
|
|
1293
|
+
get tagName() {
|
|
1164
1294
|
return this.#_options.rootETagName;
|
|
1165
1295
|
}
|
|
1166
1296
|
|
|
1167
|
-
set tagName(value){
|
|
1297
|
+
set tagName(value) {
|
|
1168
1298
|
value = readAsString(value, true);
|
|
1169
1299
|
this.#_options.rootETagName = isNotEmptyString(
|
|
1170
1300
|
value
|
|
@@ -1172,14 +1302,14 @@ class TXmlContentRootElement extends TXmlElementController {
|
|
|
1172
1302
|
}
|
|
1173
1303
|
|
|
1174
1304
|
/**
|
|
1175
|
-
* @param {object}
|
|
1176
|
-
* @param {
|
|
1305
|
+
* @param {object} item
|
|
1306
|
+
* @param {boolean} [opt=false]
|
|
1177
1307
|
* @returns {?object}
|
|
1178
1308
|
* @protected
|
|
1179
1309
|
* @static
|
|
1180
1310
|
* @description Tries to unwraps a given object.
|
|
1181
1311
|
*/
|
|
1182
|
-
static __unwrap(item, opt){
|
|
1312
|
+
static __unwrap(item, opt) {
|
|
1183
1313
|
return (
|
|
1184
1314
|
item instanceof TXmlContentRootElement
|
|
1185
1315
|
&& (typeof opt === 'boolean' ? opt : false)
|
|
@@ -1195,17 +1325,22 @@ class TXmlContentRootElement extends TXmlElementController {
|
|
|
1195
1325
|
* that managea content of a document
|
|
1196
1326
|
*/
|
|
1197
1327
|
class TXmlContentContainer {
|
|
1198
|
-
|
|
1199
|
-
#
|
|
1200
|
-
|
|
1201
|
-
#
|
|
1202
|
-
|
|
1328
|
+
/** @property {?object} */
|
|
1329
|
+
#_content;// = null;
|
|
1330
|
+
/** @property {?object} */
|
|
1331
|
+
#_options;// = null;
|
|
1332
|
+
/** @property {?object} */
|
|
1333
|
+
#_parseOptions;// = null;
|
|
1334
|
+
/** @property {?TXmlContentDeclaration} */
|
|
1335
|
+
#_docDecl;// = null;
|
|
1336
|
+
/** @property {?TXmlContentRootElement} */
|
|
1337
|
+
#_docRoot;// = null;
|
|
1203
1338
|
|
|
1204
1339
|
/**
|
|
1205
1340
|
* @param {object} [opt]
|
|
1206
1341
|
* @param {object} [opt.parseOptions]
|
|
1207
1342
|
*/
|
|
1208
|
-
constructor(opt){
|
|
1343
|
+
constructor(opt) {
|
|
1209
1344
|
// load options
|
|
1210
1345
|
const _options = isPlainObject(opt) ? opt : {};
|
|
1211
1346
|
let { parseOptions } = _options;
|
|
@@ -1230,26 +1365,27 @@ class TXmlContentContainer {
|
|
|
1230
1365
|
* @property {TXmlContentRootElement}
|
|
1231
1366
|
* @readonly
|
|
1232
1367
|
*/
|
|
1233
|
-
get rootElement(){
|
|
1368
|
+
get rootElement() {
|
|
1234
1369
|
return this.#_docRoot;
|
|
1235
1370
|
}
|
|
1236
1371
|
|
|
1237
1372
|
/**
|
|
1238
|
-
* @returns {
|
|
1373
|
+
* @returns {void}
|
|
1239
1374
|
* @description Cleans a document content.
|
|
1240
1375
|
*/
|
|
1241
|
-
clear(){
|
|
1376
|
+
clear() {
|
|
1242
1377
|
this.#_docDecl.init();
|
|
1243
1378
|
this.rootElement.clear();
|
|
1244
1379
|
}
|
|
1245
1380
|
|
|
1246
1381
|
/**
|
|
1247
|
-
* @param {object}
|
|
1248
|
-
* @
|
|
1382
|
+
* @param {object} obj
|
|
1383
|
+
* @param {object} [opt]
|
|
1384
|
+
* @returns {boolean}
|
|
1249
1385
|
* @protected
|
|
1250
1386
|
* @description Initializes an instance with a given content.
|
|
1251
1387
|
*/
|
|
1252
|
-
_bindContent(obj, opt){
|
|
1388
|
+
_bindContent(obj, opt) {
|
|
1253
1389
|
const _options = isPlainObject(opt) ? opt : this.#_options;
|
|
1254
1390
|
let isSUCCEED = false;
|
|
1255
1391
|
if (isPlainObject(obj)) {
|
|
@@ -1281,7 +1417,7 @@ class TXmlContentContainer {
|
|
|
1281
1417
|
* @returns {string}
|
|
1282
1418
|
* @description Returns a document content as a string in an XML-format.
|
|
1283
1419
|
*/
|
|
1284
|
-
saveToXMLString(){
|
|
1420
|
+
saveToXMLString() {
|
|
1285
1421
|
let result = '';
|
|
1286
1422
|
try {
|
|
1287
1423
|
result = xmlParser.js2xml(this.#_content, this.#_parseOptions.js2xml);
|
|
@@ -1293,13 +1429,13 @@ class TXmlContentContainer {
|
|
|
1293
1429
|
}
|
|
1294
1430
|
|
|
1295
1431
|
/**
|
|
1296
|
-
* @param {string}
|
|
1432
|
+
* @param {string} source
|
|
1297
1433
|
* @returns {object}
|
|
1298
1434
|
* @throws {Error}
|
|
1299
1435
|
* @async
|
|
1300
1436
|
* @description Saves a document content to a file.
|
|
1301
1437
|
*/
|
|
1302
|
-
saveToFile(source){
|
|
1438
|
+
saveToFile(source) {
|
|
1303
1439
|
/**/// main part that return promise as a result
|
|
1304
1440
|
return new Promise((resolve, reject) => {
|
|
1305
1441
|
let data = {
|
|
@@ -1337,12 +1473,12 @@ class TXmlContentContainer {
|
|
|
1337
1473
|
}
|
|
1338
1474
|
|
|
1339
1475
|
/**
|
|
1340
|
-
* @param {string}
|
|
1476
|
+
* @param {string} source
|
|
1341
1477
|
* @returns {object}
|
|
1342
1478
|
* @throws {Error}
|
|
1343
1479
|
* @description Saves a document content to a file.
|
|
1344
1480
|
*/
|
|
1345
|
-
saveToFileSync(source){
|
|
1481
|
+
saveToFileSync(source) {
|
|
1346
1482
|
let data = {
|
|
1347
1483
|
isSucceed: false,
|
|
1348
1484
|
source: typeof source === 'string' ? source.trim() : '',
|
|
@@ -1374,12 +1510,12 @@ class TXmlContentContainer {
|
|
|
1374
1510
|
}
|
|
1375
1511
|
|
|
1376
1512
|
/**
|
|
1377
|
-
* @param {string}
|
|
1378
|
-
* @returns {
|
|
1513
|
+
* @param {string} loadFromXMLString
|
|
1514
|
+
* @returns {boolean}
|
|
1379
1515
|
* @throws {Error}
|
|
1380
1516
|
* @description Loads a document content from a string.
|
|
1381
1517
|
*/
|
|
1382
|
-
loadFromXMLString(xmlString){
|
|
1518
|
+
loadFromXMLString(xmlString) {
|
|
1383
1519
|
let isSUCCEED = false;
|
|
1384
1520
|
if (typeof xmlString === 'string') {
|
|
1385
1521
|
let obj = null;
|
|
@@ -1398,13 +1534,13 @@ class TXmlContentContainer {
|
|
|
1398
1534
|
}
|
|
1399
1535
|
|
|
1400
1536
|
/**
|
|
1401
|
-
* @param {string}
|
|
1537
|
+
* @param {string} source
|
|
1402
1538
|
* @returns {object}
|
|
1403
1539
|
* @throws {Error}
|
|
1404
1540
|
* @async
|
|
1405
1541
|
* @description Loads a document content from a file.
|
|
1406
1542
|
*/
|
|
1407
|
-
loadFromFile(source){
|
|
1543
|
+
loadFromFile(source) {
|
|
1408
1544
|
/**/// main part that return promise as a result
|
|
1409
1545
|
return new Promise((resolve, reject) => {
|
|
1410
1546
|
let data = {
|
|
@@ -1452,12 +1588,12 @@ class TXmlContentContainer {
|
|
|
1452
1588
|
}
|
|
1453
1589
|
|
|
1454
1590
|
/**
|
|
1455
|
-
* @param {string}
|
|
1591
|
+
* @param {string} source
|
|
1456
1592
|
* @returns {object}
|
|
1457
1593
|
* @throws {Error}
|
|
1458
1594
|
* @description Loads a document content from a file.
|
|
1459
1595
|
*/
|
|
1460
|
-
loadFromFileSync(source){
|
|
1596
|
+
loadFromFileSync(source) {
|
|
1461
1597
|
let data = {
|
|
1462
1598
|
isLoaded: false,
|
|
1463
1599
|
source: typeof source === 'string' ? source.trim() : '',
|
|
@@ -1504,7 +1640,7 @@ class TXmlContentContainer {
|
|
|
1504
1640
|
* @protected
|
|
1505
1641
|
* @description Returns a document content a string in a JSON-format.
|
|
1506
1642
|
*/
|
|
1507
|
-
asJSON(){
|
|
1643
|
+
asJSON() {
|
|
1508
1644
|
return JSON.stringify(this.#_content, null, 2);
|
|
1509
1645
|
}
|
|
1510
1646
|
|