@cntwg/xml-lib-js 0.0.24 → 0.0.26
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 +19 -0
- package/LICENSE +1 -1
- package/README.md +17 -10
- package/doc/xmldoc-lib.md +104 -49
- package/index.js +13 -16
- package/lib/xml-helper.js +88 -0
- package/lib/xmldoc-lib.js +462 -84
- package/package.json +12 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
#### *v0.0.26*
|
|
2
|
+
|
|
3
|
+
Pre-release version.
|
|
4
|
+
|
|
5
|
+
> - `xmldoc-lib.md` updated;
|
|
6
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.2.1;
|
|
7
|
+
> - updated dependency on `@ygracs/xobj-lib-js` module to v0.1.2;
|
|
8
|
+
> - improve error handling on file load/save ops for `TXmlContentContainer`;
|
|
9
|
+
> - fix behavior for a `setTextValue` method of a `TXmlElementController`;
|
|
10
|
+
> - add `xml-helper.js` module.
|
|
11
|
+
|
|
12
|
+
#### *v0.0.25*
|
|
13
|
+
|
|
14
|
+
Pre-release version.
|
|
15
|
+
|
|
16
|
+
> - `xmldoc-lib.md` updated;
|
|
17
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.2.0;
|
|
18
|
+
> - updated dependency on `@ygracs/xobj-lib-js` module to v0.1.1.
|
|
19
|
+
|
|
1
20
|
#### *v0.0.24*
|
|
2
21
|
|
|
3
22
|
Pre-release version.
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2019-
|
|
3
|
+
Copyright (c) 2019-2024 Yuri Grachev
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/README.md
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|***rev.*:**|0.1.
|
|
1
|
+
|***rev.*:**|0.1.5|
|
|
2
2
|
|:---|---:|
|
|
3
|
-
|***date***:|
|
|
3
|
+
|***date***:|2024-06-26|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
7
7
|
This module provide a base functionality for handling an XML-documents.
|
|
8
8
|
|
|
9
|
-
## Use cases
|
|
10
|
-
|
|
11
|
-
### Installation
|
|
12
|
-
|
|
13
|
-
`npm install @cntwg/xml-lib-js`
|
|
14
|
-
|
|
15
9
|
## Description
|
|
16
10
|
|
|
17
11
|
This module contains the following components:
|
|
@@ -26,8 +20,6 @@ xObj-manipulator is a set of functions (see docs for [`@ygracs/xobj-lib-js` modu
|
|
|
26
20
|
|
|
27
21
|
+ `XML_DEF_ROOT_ETAG_NAME`;
|
|
28
22
|
+ `XML_DEF_PARSE_OPTIONS`;
|
|
29
|
-
+ `DEF_XML_ROOT_ETAG_NAME` (*will deprecate*);
|
|
30
|
-
+ `DEF_XML_PARSE_OPTIONS` (*will deprecate*).
|
|
31
23
|
|
|
32
24
|
- classes:
|
|
33
25
|
|
|
@@ -40,3 +32,18 @@ xObj-manipulator is a set of functions (see docs for [`@ygracs/xobj-lib-js` modu
|
|
|
40
32
|
+ `TXmlContentContainer`.
|
|
41
33
|
|
|
42
34
|
For more read the `xmldoc-lib.md` in the project `doc` directory.
|
|
35
|
+
|
|
36
|
+
### 3. an `xmlHelper` module extention
|
|
37
|
+
|
|
38
|
+
- functions:
|
|
39
|
+
|
|
40
|
+
+ `getChildByPath`;
|
|
41
|
+
+ `addChildByPath`.
|
|
42
|
+
|
|
43
|
+
For more read the `xmldoc-lib.md` in the project `doc` directory.
|
|
44
|
+
|
|
45
|
+
## Use cases
|
|
46
|
+
|
|
47
|
+
### Installation
|
|
48
|
+
|
|
49
|
+
`npm install @cntwg/xml-lib-js`
|
package/doc/xmldoc-lib.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.23|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|
|
|
3
|
+
>|date:|2024-06-26|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ This paper describes a constants and an object classes provided by `xmldoc-lib.j
|
|
|
8
8
|
|
|
9
9
|
## Module constants
|
|
10
10
|
|
|
11
|
-
### **
|
|
11
|
+
### **XML\_DEF\_PARSE_OPTIONS**
|
|
12
12
|
|
|
13
13
|
This constant object provided by the module contains a default settings of options for XML-parser module used within.
|
|
14
14
|
|
|
@@ -37,14 +37,10 @@ The settings listed in the table below:
|
|
|
37
37
|
|`trim`|`boolean`|`true`|
|
|
38
38
|
|`spaces`|`number`|`2`|
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### **DEF\_XML\_ROOT\_ETAG_NAME** or **XML\_DEF\_ROOT\_ETAG_NAME**
|
|
40
|
+
### **XML\_DEF\_ROOT\_ETAG_NAME**
|
|
43
41
|
|
|
44
42
|
This constant defines a default value for naming the root element for XML-document. Its value is `root`.
|
|
45
43
|
|
|
46
|
-
> WARNING: The constant `DEF\_XML\_ROOT\_ETAG_NAME` is deprecate. Use `XML\_DEF\_ROOT\_ETAG_NAME` instead.
|
|
47
|
-
|
|
48
44
|
## Module classes
|
|
49
45
|
|
|
50
46
|
### **TXmlContentParseOptions**
|
|
@@ -82,26 +78,32 @@ This class implements a proxy interface for handling attributes of an element.
|
|
|
82
78
|
|
|
83
79
|
#### class constructor
|
|
84
80
|
|
|
85
|
-
The class constructor creates a new instance of the class.
|
|
81
|
+
The class constructor creates a new instance of the class.
|
|
86
82
|
|
|
87
|
-
|
|
83
|
+
##### constructor parameters
|
|
84
|
+
|
|
85
|
+
The class constructor receives an arguments listed below:
|
|
86
|
+
|
|
87
|
+
|parameter name|value type|default value|description|
|
|
88
88
|
|:---|---|---:|:---|
|
|
89
89
|
|`object`|---|---|a host object that holds an attributes|
|
|
90
90
|
|`options`|`object`|---|an options settings|
|
|
91
91
|
|
|
92
|
+
> NOTE: if `object` parameter is not a plain object the `TypeError` thrown.
|
|
93
|
+
|
|
94
|
+
##### `options` parameter
|
|
95
|
+
|
|
92
96
|
The `options` structure is listed below:
|
|
93
97
|
|
|
94
98
|
|option name|value type|default value|description|
|
|
95
99
|
|:---|---|---:|:---|
|
|
96
100
|
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (*see description for `XML_DEF_PARSE_OPTIONS`*)|
|
|
97
101
|
|
|
98
|
-
> NOTE: if `object` parameter is not a plain object the `TypeError` thrown.
|
|
99
|
-
|
|
100
102
|
#### class properties
|
|
101
103
|
|
|
102
|
-
|name|read only|description|
|
|
103
|
-
|
|
104
|
-
|`entries`|yes|returns array of entries for all existing attributes|
|
|
104
|
+
|property name|value type|read only|description|
|
|
105
|
+
|:---|---|---|:---|
|
|
106
|
+
|`entries`|`array`|yes|returns an array of entries for all existing attributes|
|
|
105
107
|
|
|
106
108
|
|
|
107
109
|
#### class methods
|
|
@@ -132,13 +134,19 @@ This class implements a proxy interface for an element.
|
|
|
132
134
|
|
|
133
135
|
#### class constructor
|
|
134
136
|
|
|
135
|
-
The class constructor creates a new instance of the class.
|
|
137
|
+
The class constructor creates a new instance of the class.
|
|
136
138
|
|
|
137
|
-
|
|
139
|
+
##### constructor parameters
|
|
140
|
+
|
|
141
|
+
The class constructor receives an arguments listed below:
|
|
142
|
+
|
|
143
|
+
|parameter name|value type|default value|description|
|
|
138
144
|
|:---|---|---:|:---|
|
|
139
145
|
|`object`|---|---|a host object|
|
|
140
146
|
|`options`|`object`|---|an options settings|
|
|
141
147
|
|
|
148
|
+
##### `options` parameter
|
|
149
|
+
|
|
142
150
|
The `options` structure is listed below:
|
|
143
151
|
|
|
144
152
|
|option name|value type|default value|description|
|
|
@@ -148,11 +156,11 @@ The `options` structure is listed below:
|
|
|
148
156
|
|
|
149
157
|
#### class properties
|
|
150
158
|
|
|
151
|
-
|property name|read only|description|
|
|
152
|
-
|
|
153
|
-
|`attributes`|yes|returns an attributes of the element|
|
|
154
|
-
|`name
|
|
155
|
-
|`textValue`|no|represents a value of the element|
|
|
159
|
+
|property name|value type|read only|description|
|
|
160
|
+
|:---|---|---|:---|
|
|
161
|
+
|`attributes`|`TXmlAttributesMapper`|yes|returns an attributes of the element|
|
|
162
|
+
|`name`||yes|\<*reserved*>|
|
|
163
|
+
|`textValue`|`string`|no|represents a value of the element|
|
|
156
164
|
|
|
157
165
|
#### class methods
|
|
158
166
|
|
|
@@ -181,6 +189,7 @@ This method returns an array witch contain a value of a `textValue` property and
|
|
|
181
189
|
This method sets the value of a `textValue` property and its `lang` attribute and if succeed returns `true`.
|
|
182
190
|
|
|
183
191
|
The method received value that can be a string or an array. If value is an array it must be in the following format:
|
|
192
|
+
|
|
184
193
|
`[ <textValue> ]`
|
|
185
194
|
or
|
|
186
195
|
`[ <lang>, <textValue> ]`.
|
|
@@ -237,13 +246,19 @@ This class implements a proxy interface for a list of elements.
|
|
|
237
246
|
|
|
238
247
|
#### class constructor
|
|
239
248
|
|
|
240
|
-
The class constructor creates a new instance of the class.
|
|
249
|
+
The class constructor creates a new instance of the class.
|
|
241
250
|
|
|
242
|
-
|
|
251
|
+
##### constructor parameters
|
|
252
|
+
|
|
253
|
+
The class constructor receives an arguments listed below:
|
|
254
|
+
|
|
255
|
+
|parameter name|value type|default value|description|
|
|
243
256
|
|:---|---|---:|:---|
|
|
244
257
|
|`object`|---|---|a host object of an array type.|
|
|
245
258
|
|`options`|`object`|---|an options settings.|
|
|
246
259
|
|
|
260
|
+
##### `options` parameter
|
|
261
|
+
|
|
247
262
|
The `options` structure is listed below:
|
|
248
263
|
|
|
249
264
|
|option name|value type|default value|description|
|
|
@@ -255,7 +270,7 @@ The `options` structure is listed below:
|
|
|
255
270
|
#### class properties
|
|
256
271
|
|
|
257
272
|
|property name|property type|read only|description|
|
|
258
|
-
|
|
273
|
+
|:---|---|---|:---|
|
|
259
274
|
|`count`|`number`|yes|returns a quantity of the elements|
|
|
260
275
|
|`size`|`number`|yes|returns a quantity of the elements|
|
|
261
276
|
|`maxIndex`|`index`|yes|returns a last possible index of the elements|
|
|
@@ -337,13 +352,19 @@ This class implements a proxy interface for a document declaration element.
|
|
|
337
352
|
|
|
338
353
|
#### class constructor
|
|
339
354
|
|
|
340
|
-
The class constructor creates a new instance of the class.
|
|
355
|
+
The class constructor creates a new instance of the class.
|
|
341
356
|
|
|
342
|
-
|
|
357
|
+
##### constructor parameters
|
|
358
|
+
|
|
359
|
+
The class constructor receives an arguments listed below:
|
|
360
|
+
|
|
361
|
+
|parameter name|value type|default value|description|
|
|
343
362
|
|:---|---|---:|:---|
|
|
344
363
|
|`object`|`object`|---|a host object for the document content.|
|
|
345
364
|
|`options`|`object`|---|an options settings.|
|
|
346
365
|
|
|
366
|
+
##### `options` parameter
|
|
367
|
+
|
|
347
368
|
The `options` structure is listed below:
|
|
348
369
|
|
|
349
370
|
|option name|value type|default value|description|
|
|
@@ -353,7 +374,7 @@ The `options` structure is listed below:
|
|
|
353
374
|
#### class properties
|
|
354
375
|
|
|
355
376
|
|property name|property type|read only|description|
|
|
356
|
-
|
|
377
|
+
|:---|---|---|:---|
|
|
357
378
|
|`version`|`string`|no|returns a version of a XML|
|
|
358
379
|
|`encoding`|`string`|no|returns an encodings used by a document|
|
|
359
380
|
|
|
@@ -361,21 +382,27 @@ The `options` structure is listed below:
|
|
|
361
382
|
|
|
362
383
|
##### **init()**
|
|
363
384
|
|
|
364
|
-
This method initializes element with a default values.
|
|
385
|
+
This method initializes an element with a default values.
|
|
365
386
|
|
|
366
387
|
### **TXmlContentRootElement**
|
|
367
388
|
|
|
368
|
-
This class extends functionality of a `TXmlElementController` class.
|
|
389
|
+
This class extends a functionality of a `TXmlElementController` class.
|
|
369
390
|
|
|
370
391
|
#### class constructor
|
|
371
392
|
|
|
372
|
-
The class constructor creates a new instance of the class.
|
|
393
|
+
The class constructor creates a new instance of the class.
|
|
373
394
|
|
|
374
|
-
|
|
395
|
+
##### constructor parameters
|
|
396
|
+
|
|
397
|
+
The class constructor receives an arguments listed below:
|
|
398
|
+
|
|
399
|
+
|parameter name|value type|default value|description|
|
|
375
400
|
|:---|---|---:|:---|
|
|
376
401
|
|`object`|`object`|---|a host object for the document content|
|
|
377
402
|
|`options`|`object`|---|an options settings|
|
|
378
403
|
|
|
404
|
+
##### `options` parameter
|
|
405
|
+
|
|
379
406
|
The `options` structure is listed below:
|
|
380
407
|
|
|
381
408
|
|option name|value type|default value|description|
|
|
@@ -388,9 +415,9 @@ The `options` structure is listed below:
|
|
|
388
415
|
|
|
389
416
|
#### class properties
|
|
390
417
|
|
|
391
|
-
|name|read only|description|
|
|
392
|
-
|
|
393
|
-
|tagName
|
|
418
|
+
|property name|value type|read only|description|
|
|
419
|
+
|:---|---|---|:---|
|
|
420
|
+
|tagName|`string`|no||
|
|
394
421
|
|
|
395
422
|
#### class methods (*static*)
|
|
396
423
|
|
|
@@ -408,7 +435,13 @@ This class implements a proxy interface for manipulate a content of a document.
|
|
|
408
435
|
|
|
409
436
|
#### class constructor
|
|
410
437
|
|
|
411
|
-
The class constructor creates a new instance of the class.
|
|
438
|
+
The class constructor creates a new instance of the class.
|
|
439
|
+
|
|
440
|
+
##### constructor parameters
|
|
441
|
+
|
|
442
|
+
The class constructor receives an `options` parameter as its argument.
|
|
443
|
+
|
|
444
|
+
##### `options` parameter
|
|
412
445
|
|
|
413
446
|
The `options` structure is listed below:
|
|
414
447
|
|
|
@@ -422,9 +455,9 @@ The `options` structure is listed below:
|
|
|
422
455
|
|
|
423
456
|
#### class properties
|
|
424
457
|
|
|
425
|
-
|property name|read only|description|
|
|
426
|
-
|
|
427
|
-
|rootElement
|
|
458
|
+
|property name|value type|read only|description|
|
|
459
|
+
|:---|---|---|:---|
|
|
460
|
+
|rootElement||yes|returns a document root element|
|
|
428
461
|
|
|
429
462
|
#### class methods
|
|
430
463
|
|
|
@@ -436,12 +469,6 @@ This method clears a document content.
|
|
|
436
469
|
|
|
437
470
|
This method returns a document content as a string.
|
|
438
471
|
|
|
439
|
-
##### **saveToFile(src)**
|
|
440
|
-
|
|
441
|
-
This method saves a document content into a file addressed by `src`.
|
|
442
|
-
|
|
443
|
-
> This is `async` method.
|
|
444
|
-
|
|
445
472
|
##### **saveToFileSync(src)**
|
|
446
473
|
|
|
447
474
|
This method saves a document content into a file addressed by `src`.
|
|
@@ -450,13 +477,17 @@ This method saves a document content into a file addressed by `src`.
|
|
|
450
477
|
|
|
451
478
|
This method loads a document content from a string given by `str`.
|
|
452
479
|
|
|
453
|
-
##### **
|
|
480
|
+
##### **loadFromFileSync(src)**
|
|
454
481
|
|
|
455
482
|
This method loads a document content from a file addressed by `src`.
|
|
456
483
|
|
|
457
|
-
|
|
484
|
+
#### class methods (*async*)
|
|
458
485
|
|
|
459
|
-
##### **
|
|
486
|
+
##### **saveToFile(src)**
|
|
487
|
+
|
|
488
|
+
This method saves a document content into a file addressed by `src`.
|
|
489
|
+
|
|
490
|
+
##### **loadFromFile(src)**
|
|
460
491
|
|
|
461
492
|
This method loads a document content from a file addressed by `src`.
|
|
462
493
|
|
|
@@ -470,4 +501,28 @@ This method returns a document content as a string in the JSON-format.
|
|
|
470
501
|
|
|
471
502
|
This method binds a given object as a document content.
|
|
472
503
|
|
|
473
|
-
For `options` parameter details see the class
|
|
504
|
+
For `options` parameter details see the class constructor description.
|
|
505
|
+
|
|
506
|
+
## Module `xmlHelper`
|
|
507
|
+
|
|
508
|
+
This section contains functions provided by `xmlHelper` module.
|
|
509
|
+
|
|
510
|
+
### Experimental functions
|
|
511
|
+
|
|
512
|
+
> Note: Purpose of those functions will be discussed and some may be deprecate and make obsolete or functionality may be altered. So use it with cautions in mind.
|
|
513
|
+
|
|
514
|
+
#### **getChildByPath(object, chain)**
|
|
515
|
+
|
|
516
|
+
> since: \[v0.0.26]
|
|
517
|
+
|
|
518
|
+
This function tries to get a child element from a given object following path provided by `chain` parameter. If failed `null` is returned.
|
|
519
|
+
|
|
520
|
+
The `chain` parameter contains an array of an element names.
|
|
521
|
+
|
|
522
|
+
#### **addChildByPath(object, chain)**
|
|
523
|
+
|
|
524
|
+
> since: \[v0.0.26]
|
|
525
|
+
|
|
526
|
+
This function tries to add a new child element into a given object following path provided by `chain` parameter. If succeed a new element returned. If failed `null` is returned.
|
|
527
|
+
|
|
528
|
+
The `chain` parameter contains an array of an element names. The last name in `chain` is a name of the element which will be added.
|
package/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.012-20240626]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
5
5
|
const xObj = require('@ygracs/xobj-lib-js');
|
|
6
6
|
const xmldoc = require('./lib/xmldoc-lib.js');
|
|
7
|
+
const xmlHelper = require('./lib/xml-helper.js');
|
|
7
8
|
|
|
8
9
|
// === module extra block (helper functions) ===
|
|
9
10
|
|
|
@@ -11,21 +12,17 @@ const xmldoc = require('./lib/xmldoc-lib.js');
|
|
|
11
12
|
|
|
12
13
|
// === module exports block ===
|
|
13
14
|
|
|
14
|
-
exports.xObj = xObj;
|
|
15
|
+
module.exports.xObj = xObj;
|
|
16
|
+
module.exports.xmlHelper = xmlHelper;
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
exports.
|
|
18
|
-
// will deprecate
|
|
19
|
-
exports.DEF_XML_ROOT_ETAG_NAME = xmldoc.XML_DEF_ROOT_ETAG_NAME;
|
|
18
|
+
module.exports.XML_DEF_PARSE_OPTIONS = xmldoc.XML_DEF_PARSE_OPTIONS;
|
|
19
|
+
module.exports.XML_DEF_ROOT_ETAG_NAME = xmldoc.XML_DEF_ROOT_ETAG_NAME;
|
|
20
20
|
|
|
21
|
-
exports.
|
|
22
|
-
exports.XML_DEF_ROOT_ETAG_NAME = xmldoc.XML_DEF_ROOT_ETAG_NAME;
|
|
21
|
+
module.exports.TXmlContentParseOptions = xmldoc.TXmlContentParseOptions;
|
|
23
22
|
|
|
24
|
-
exports.
|
|
25
|
-
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.
|
|
30
|
-
exports.TXmlContentRootElement = xmldoc.TXmlContentRootElement;
|
|
31
|
-
exports.TXmlContentContainer = xmldoc.TXmlContentContainer;
|
|
23
|
+
module.exports.TXmlAttributesMapper = xmldoc.TXmlAttributesMapper;
|
|
24
|
+
module.exports.TXmlElementController = xmldoc.TXmlElementController;
|
|
25
|
+
module.exports.TXmlElementsListController = xmldoc.TXmlElementsListController;
|
|
26
|
+
module.exports.TXmlContentDeclaration = xmldoc.TXmlContentDeclaration;
|
|
27
|
+
module.exports.TXmlContentRootElement = xmldoc.TXmlContentRootElement;
|
|
28
|
+
module.exports.TXmlContentContainer = xmldoc.TXmlContentContainer;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// [v0.0.001-20240626]
|
|
2
|
+
|
|
3
|
+
// === module init block ===
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
valueToArray,
|
|
7
|
+
} = require('@ygracs/bsfoc-lib-js');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
TXmlElementController,
|
|
11
|
+
} = require('./xmldoc-lib');
|
|
12
|
+
|
|
13
|
+
// === module extra block (helper functions) ===
|
|
14
|
+
|
|
15
|
+
// === module main block ===
|
|
16
|
+
|
|
17
|
+
/***
|
|
18
|
+
* (* constant definitions *)
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/***
|
|
22
|
+
* (* function definitions *)
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @function getChildByPath
|
|
27
|
+
* @param {TXmlElementController}
|
|
28
|
+
* @param {array}
|
|
29
|
+
* @returns {?TXmlElementController}
|
|
30
|
+
* @description Tries to get a child element.
|
|
31
|
+
*/
|
|
32
|
+
function getChildByPath(obj, chain) {
|
|
33
|
+
let result = null;
|
|
34
|
+
if (obj instanceof TXmlElementController) {
|
|
35
|
+
const list = valueToArray(chain);
|
|
36
|
+
let child = obj;
|
|
37
|
+
let isFound = false;
|
|
38
|
+
for (let name of list) {
|
|
39
|
+
child = child.getChild(name);
|
|
40
|
+
if (
|
|
41
|
+
child !== null
|
|
42
|
+
&& (child instanceof TXmlElementController)
|
|
43
|
+
) {
|
|
44
|
+
isFound = true;
|
|
45
|
+
} else {
|
|
46
|
+
isFound = false;
|
|
47
|
+
break;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
if (isFound) result = child;
|
|
51
|
+
};
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @function addChildByPath
|
|
57
|
+
* @param {TXmlElementController}
|
|
58
|
+
* @param {array}
|
|
59
|
+
* @returns {?TXmlElementController}
|
|
60
|
+
* @description Tries to get a child element.
|
|
61
|
+
*/
|
|
62
|
+
function addChildByPath(obj, chain){
|
|
63
|
+
let child = null;
|
|
64
|
+
if (obj instanceof TXmlElementController) {
|
|
65
|
+
const list = valueToArray(chain);
|
|
66
|
+
for (let name of list) {
|
|
67
|
+
child = item.getChild(name);
|
|
68
|
+
if (child === null) {
|
|
69
|
+
child = item.addChild(name);
|
|
70
|
+
};
|
|
71
|
+
if ((child instanceof TXmlElementController)) {
|
|
72
|
+
item = child;
|
|
73
|
+
} else {
|
|
74
|
+
child = null; break;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
return child;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/***
|
|
82
|
+
* (* class definitions *)
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
// === module exports block ===
|
|
86
|
+
|
|
87
|
+
module.exports.getChildByPath = getChildByPath;
|
|
88
|
+
module.exports.addChildByPath = addChildByPath;
|