@cntwg/xml-lib-js 0.0.29 → 0.0.31
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 +23 -0
- package/doc/xmldoc-lib.md +121 -59
- package/lib/xmldoc-lib.js +414 -242
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
#### *v0.0.31*
|
|
2
|
+
|
|
3
|
+
Pre-release version.
|
|
4
|
+
|
|
5
|
+
> - `xmldoc-lib.md` updated;
|
|
6
|
+
> - (`TXmlElementController`) fix issue in method: `__setChildRaw`;
|
|
7
|
+
> - (`TXmlElementController`) add special static method: `__getChildRaw`;
|
|
8
|
+
> - (`TXmlElementController`) add special static method: `__addChildRaw`;
|
|
9
|
+
> - (`TXmlElementController`) deprecate methods: `_getChildRaw`, `_addChildRaw`< `_setChildRaw`;
|
|
10
|
+
> - some fixes in `xmldoc-lib.js` module.
|
|
11
|
+
|
|
12
|
+
#### *v0.0.30*
|
|
13
|
+
|
|
14
|
+
Pre-release version.
|
|
15
|
+
|
|
16
|
+
> - `xmldoc-lib.md` updated;
|
|
17
|
+
> - updated dependency on `@ygracs/xobj-lib-js` module to v0.2.0;
|
|
18
|
+
> - (`TXmlAttributesMapper`) add method: `renameAttribute`;
|
|
19
|
+
> - (`TXmlElementController`) add method: `renameAttribute`;
|
|
20
|
+
> - (`TXmlElementController`) add method: `loadFromXMLString`;
|
|
21
|
+
> - (`TXmlElementController`) add method: `create` (static);
|
|
22
|
+
> - (`TXmlElementController`) change class constructor behavior (*see docs for details*).
|
|
23
|
+
|
|
1
24
|
#### *v0.0.29*
|
|
2
25
|
|
|
3
26
|
Pre-release version.
|
package/doc/xmldoc-lib.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
>|***rev.*:**|0.1.
|
|
1
|
+
>|***rev.*:**|0.1.31|
|
|
2
2
|
>|:---|---:|
|
|
3
|
-
>|date:|2024-
|
|
3
|
+
>|date:|2024-09-29|
|
|
4
4
|
|
|
5
5
|
## Introduction
|
|
6
6
|
|
|
@@ -51,21 +51,21 @@ This constant defines a default value for naming the language attribute for XML-
|
|
|
51
51
|
|
|
52
52
|
> 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.
|
|
53
53
|
|
|
54
|
-
#### **readAsTagName(value)**
|
|
54
|
+
#### **readAsTagName(value)** => `string`
|
|
55
55
|
|
|
56
|
-
> since: `v0.0.28`
|
|
56
|
+
> since: \[`v0.0.28`]
|
|
57
57
|
|
|
58
58
|
This function tries to convert a given `value` to the value of type which is suitable for an XML-element's tag name. If failed an empty string is returned.
|
|
59
59
|
|
|
60
|
-
#### **readAsAttrName(value)**
|
|
60
|
+
#### **readAsAttrName(value)** => `string`
|
|
61
61
|
|
|
62
|
-
> since: `v0.0.28`
|
|
62
|
+
> since: \[`v0.0.28`]
|
|
63
63
|
|
|
64
64
|
This function tries to convert a given `value` to the value of type which is suitable for an XML-element's attribute name. If failed an empty string is returned.
|
|
65
65
|
|
|
66
66
|
#### **valueToElementID(value)**
|
|
67
67
|
|
|
68
|
-
> since: `v0.0.28`
|
|
68
|
+
> since: \[`v0.0.28`]
|
|
69
69
|
|
|
70
70
|
This function tries to convert a given `value` to the value of a valid identifier which is suitable for an XML-element's ID-attribute. If failed an empty string is returned.
|
|
71
71
|
|
|
@@ -117,9 +117,7 @@ The class constructor receives an arguments listed below:
|
|
|
117
117
|
|`object`|---|---|a host object that holds an attributes|
|
|
118
118
|
|`options`|`object`|---|an options settings|
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
##### `options` parameter
|
|
120
|
+
###### `options` parameter
|
|
123
121
|
|
|
124
122
|
The `options` structure is listed below:
|
|
125
123
|
|
|
@@ -127,6 +125,10 @@ The `options` structure is listed below:
|
|
|
127
125
|
|:---|---|---:|:---|
|
|
128
126
|
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (*see description for `XML_DEF_PARSE_OPTIONS`*)|
|
|
129
127
|
|
|
128
|
+
##### exceptions
|
|
129
|
+
|
|
130
|
+
If `object` parameter is not a type of `object` or not given a `TypeError` thrown.
|
|
131
|
+
|
|
130
132
|
#### class properties
|
|
131
133
|
|
|
132
134
|
|property name|value type|read only|description|
|
|
@@ -136,23 +138,29 @@ The `options` structure is listed below:
|
|
|
136
138
|
|
|
137
139
|
#### class methods
|
|
138
140
|
|
|
139
|
-
##### **hasAttribute(name)**
|
|
141
|
+
##### **hasAttribute(name)** => `boolean`
|
|
140
142
|
|
|
141
143
|
This method checks whether or not an attribute addressed by a `name` exists. If attribute exists, 'true' is returned.
|
|
142
144
|
|
|
143
|
-
##### **getAttribute(name)**
|
|
145
|
+
##### **getAttribute(name)** => `string`
|
|
144
146
|
|
|
145
147
|
This method returns an attribute value addressed by a `name`. If attribute is not exists the empty string is returned.
|
|
146
148
|
|
|
147
|
-
##### **setAttribute(name, value)**
|
|
149
|
+
##### **setAttribute(name, value)** => `boolean`
|
|
148
150
|
|
|
149
151
|
This method sets an attribute value addressed by a `name` and return `true` if succeed.
|
|
150
152
|
|
|
151
|
-
##### **delAttribute(name)**
|
|
153
|
+
##### **delAttribute(name)** => `boolean`
|
|
152
154
|
|
|
153
155
|
This method clears an attribute value addressed by a `name`.
|
|
154
156
|
|
|
155
|
-
##### **
|
|
157
|
+
##### **renameAttribute(name, value)** => `boolean`
|
|
158
|
+
|
|
159
|
+
> since: \[`v0.0.30`]
|
|
160
|
+
|
|
161
|
+
This method renames an attribute addressed by a `name` to its new name given by a `value` parameter.
|
|
162
|
+
|
|
163
|
+
##### **clear()** => `void`
|
|
156
164
|
|
|
157
165
|
This method clears all attributes.
|
|
158
166
|
|
|
@@ -170,10 +178,10 @@ The class constructor receives an arguments listed below:
|
|
|
170
178
|
|
|
171
179
|
|parameter name|value type|default value|description|
|
|
172
180
|
|:---|---|---:|:---|
|
|
173
|
-
|`object
|
|
181
|
+
|`object`|`object`|---|a host object|
|
|
174
182
|
|`options`|`object`|---|an options settings|
|
|
175
183
|
|
|
176
|
-
|
|
184
|
+
###### `options` parameter
|
|
177
185
|
|
|
178
186
|
The `options` structure is listed below:
|
|
179
187
|
|
|
@@ -182,6 +190,10 @@ The `options` structure is listed below:
|
|
|
182
190
|
|`proxyModeEnable`|`boolean`|`false`|<*reserved*>|
|
|
183
191
|
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (see description for `XML_DEF_PARSE_OPTIONS`)|
|
|
184
192
|
|
|
193
|
+
##### exceptions
|
|
194
|
+
|
|
195
|
+
If `object` parameter is not a type of `object` or not given a `TypeError` thrown.
|
|
196
|
+
|
|
185
197
|
#### class properties
|
|
186
198
|
|
|
187
199
|
|property name|value type|read only|description|
|
|
@@ -192,27 +204,33 @@ The `options` structure is listed below:
|
|
|
192
204
|
|
|
193
205
|
#### class methods
|
|
194
206
|
|
|
195
|
-
##### **hasAttribute(name)**
|
|
207
|
+
##### **hasAttribute(name)** => `boolean`
|
|
196
208
|
|
|
197
209
|
This method checks whether or not an attribute addressed by a `name` exists. If attribute exists, 'true' is returned.
|
|
198
210
|
|
|
199
|
-
##### **getAttribute(name)**
|
|
211
|
+
##### **getAttribute(name)** => `string`
|
|
200
212
|
|
|
201
213
|
This method returns an attribute value addressed by a `name`. If attribute is not exists the empty string is returned.
|
|
202
214
|
|
|
203
|
-
##### **setAttribute(name, value)**
|
|
215
|
+
##### **setAttribute(name, value)** => `boolean`
|
|
204
216
|
|
|
205
217
|
This method sets an attribute value addressed by a `name` and return `true` if succeed.
|
|
206
218
|
|
|
207
|
-
##### **delAttribute(name)**
|
|
219
|
+
##### **delAttribute(name)** => `boolean`
|
|
208
220
|
|
|
209
|
-
This method clears an attribute value addressed by a `name
|
|
221
|
+
This method clears an attribute value addressed by a `name` parameter.
|
|
222
|
+
|
|
223
|
+
##### **renameAttribute(name, value)** => `boolean`
|
|
210
224
|
|
|
211
|
-
|
|
225
|
+
> since: \[`v0.0.30`]
|
|
226
|
+
|
|
227
|
+
This method renames an attribute addressed by a `name` to its new name given by a `value` parameter.
|
|
228
|
+
|
|
229
|
+
##### **getTextValue()** => `array`
|
|
212
230
|
|
|
213
231
|
This method returns an array witch contain a value of a `textValue` property and a value of a `lang` attribute in format: `[ <lang>, <textValue> ]`. If element has no `lang` attribute, it replaced by an empty string in the result.
|
|
214
232
|
|
|
215
|
-
##### **setTextValue(value)**
|
|
233
|
+
##### **setTextValue(value)** => `boolean`
|
|
216
234
|
|
|
217
235
|
This method sets the value of a `textValue` property and its `lang` attribute and if succeed returns `true`.
|
|
218
236
|
|
|
@@ -222,51 +240,87 @@ The method received value that can be a string or an array. If value is an array
|
|
|
222
240
|
or
|
|
223
241
|
`[ <lang>, <textValue> ]`.
|
|
224
242
|
|
|
225
|
-
##### **hasChild(name)**
|
|
243
|
+
##### **hasChild(name)** => `boolean`
|
|
226
244
|
|
|
227
245
|
This method checks whether or not a child element addressed by `name` is exists.
|
|
228
246
|
|
|
229
|
-
##### **getChild(name)**
|
|
247
|
+
##### **getChild(name)** => `?(TXmlElementController|TXmlElementsListController)`
|
|
230
248
|
|
|
231
249
|
This method returns a child element addressed by `name`. If failed `null` is returned.
|
|
232
250
|
|
|
233
|
-
##### **addChild(name)**
|
|
251
|
+
##### **addChild(name)** => `?TXmlElementController`
|
|
234
252
|
|
|
235
|
-
This method adds
|
|
253
|
+
This method adds a new element as a child element addressed by a `name` parameter.
|
|
236
254
|
|
|
237
|
-
##### **delChild(name)**
|
|
255
|
+
##### **delChild(name)** => `boolean`
|
|
238
256
|
|
|
239
257
|
This method deletes a child element addressed by a `name`.
|
|
240
258
|
|
|
241
259
|
> Warning: A method not fully implemented yet. Not use it for list like elements. If list contains a more than one element, a method will fail.
|
|
242
260
|
|
|
243
|
-
##### **clear()**
|
|
261
|
+
##### **clear()** => `void`
|
|
244
262
|
|
|
245
263
|
This method clears an element content.
|
|
246
264
|
|
|
265
|
+
#### class methods (*experimental*)
|
|
266
|
+
|
|
267
|
+
> Note: Purpose of those methods will be discussed and some may be deprecate and make obsolete or functionality may be altered. So use it with cautions in mind.
|
|
268
|
+
|
|
269
|
+
##### **loadFromXMLString(str)** => `boolean`
|
|
270
|
+
|
|
271
|
+
This method loads an element content from a string given by a `str` parameter.
|
|
272
|
+
|
|
273
|
+
###### *exceptions*
|
|
274
|
+
|
|
275
|
+
This methods trows `Error` if something goes wrong through a parsing process of a string.
|
|
276
|
+
|
|
247
277
|
#### class methods (*special*)
|
|
248
278
|
|
|
249
|
-
##### **_getChildRaw(name)**
|
|
279
|
+
##### **_getChildRaw(name)** => `?any`
|
|
250
280
|
|
|
251
|
-
|
|
281
|
+
> WARNING: **\[since `v0.0.31`]** this method deprecated (*use static `__getChildRaw` method of the class*).
|
|
252
282
|
|
|
253
|
-
##### **_addChildRaw(name)**
|
|
283
|
+
##### **_addChildRaw(name)** => `?object`
|
|
254
284
|
|
|
255
|
-
|
|
285
|
+
> WARNING: **\[since `v0.0.31`]** this method deprecated (*use static `__addChildRaw` method of the class*).
|
|
256
286
|
|
|
257
|
-
##### **_setChildRaw(name, obj)**
|
|
287
|
+
##### **_setChildRaw(name, obj)** => `boolean`
|
|
258
288
|
|
|
259
|
-
|
|
289
|
+
> WARNING: **\[since `v0.0.31`]** this method deprecated (*use static `__setChildRaw` method of the class*).
|
|
260
290
|
|
|
261
291
|
#### class methods (*static*)
|
|
262
292
|
|
|
263
|
-
##### **
|
|
293
|
+
##### **clear(item)** => `void`
|
|
294
|
+
|
|
295
|
+
This method clears an `item` content.
|
|
296
|
+
|
|
297
|
+
##### **create(obj, opt)** => `?(TXmlElementController|TXmlElementsListController)`
|
|
298
|
+
|
|
299
|
+
> since: \[`v0.0.30`]
|
|
300
|
+
|
|
301
|
+
This method creates an instance from a given object.
|
|
302
|
+
|
|
303
|
+
#### class methods (*static, special*)
|
|
304
|
+
|
|
305
|
+
##### **__unwrap(node)** => `?object`
|
|
264
306
|
|
|
265
307
|
This method returns a host for an element as an object. If failed `null` is returned.
|
|
266
308
|
|
|
267
|
-
##### **
|
|
309
|
+
##### **__getChildRaw(node, name)** => `?any`
|
|
268
310
|
|
|
269
|
-
|
|
311
|
+
> since: \[`v0.0.31`]
|
|
312
|
+
|
|
313
|
+
This method returns a child element addressed by `name` as object. If failed `null` is returned.
|
|
314
|
+
|
|
315
|
+
##### **__addChildRaw(node, name)** => `?object`
|
|
316
|
+
|
|
317
|
+
> since: \[`v0.0.31`]
|
|
318
|
+
|
|
319
|
+
This method adds an element addressed by `name` as a child element.
|
|
320
|
+
|
|
321
|
+
##### **__setChildRaw(node, name, obj)** => `boolean`
|
|
322
|
+
|
|
323
|
+
This method inserts a given object as a child element addressed by `name`.
|
|
270
324
|
|
|
271
325
|
### **TXmlElementsListController**
|
|
272
326
|
|
|
@@ -282,10 +336,10 @@ The class constructor receives an arguments listed below:
|
|
|
282
336
|
|
|
283
337
|
|parameter name|value type|default value|description|
|
|
284
338
|
|:---|---|---:|:---|
|
|
285
|
-
|`object
|
|
339
|
+
|`object`|`array`|---|a host object of an array type.|
|
|
286
340
|
|`options`|`object`|---|an options settings.|
|
|
287
341
|
|
|
288
|
-
|
|
342
|
+
###### `options` parameter
|
|
289
343
|
|
|
290
344
|
The `options` structure is listed below:
|
|
291
345
|
|
|
@@ -295,6 +349,10 @@ The `options` structure is listed below:
|
|
|
295
349
|
|`isNullItemsAllowed`|`boolean`|`false`|<*reserved*>|
|
|
296
350
|
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (see description for `XML_DEF_PARSE_OPTIONS`)|
|
|
297
351
|
|
|
352
|
+
##### exceptions
|
|
353
|
+
|
|
354
|
+
If `object` parameter is not a type of `array` or not given a `TypeError` may be thrown in case if a `proxyModeEnable` options is set.
|
|
355
|
+
|
|
298
356
|
#### class properties
|
|
299
357
|
|
|
300
358
|
|property name|property type|read only|description|
|
|
@@ -306,47 +364,47 @@ The `options` structure is listed below:
|
|
|
306
364
|
|
|
307
365
|
#### class methods
|
|
308
366
|
|
|
309
|
-
##### **clear()**
|
|
367
|
+
##### **clear()** => `void`
|
|
310
368
|
|
|
311
369
|
This method clears a list.
|
|
312
370
|
|
|
313
|
-
##### **isEmpty()**
|
|
371
|
+
##### **isEmpty()** => `boolean`
|
|
314
372
|
|
|
315
373
|
This method returns `true` if a list has no elements and `false` otherwise.
|
|
316
374
|
|
|
317
|
-
##### **isNotEmpty()**
|
|
375
|
+
##### **isNotEmpty()** => `boolean`
|
|
318
376
|
|
|
319
377
|
This method returns `true` if a list contains at least one element and `false` otherwise.
|
|
320
378
|
|
|
321
|
-
##### **chkIndex(index)**
|
|
379
|
+
##### **chkIndex(index)** => `boolean`
|
|
322
380
|
|
|
323
381
|
This method checks if a given index fits a range of elements within the list. If so `true` is returned.
|
|
324
382
|
|
|
325
|
-
##### **isValidItem(obj)**
|
|
383
|
+
##### **isValidItem(obj)** => `boolean`
|
|
326
384
|
|
|
327
385
|
This method checks whether or not a given element is valid.
|
|
328
386
|
|
|
329
|
-
##### **getItem(index)**
|
|
387
|
+
##### **getItem(index)** => `?TXmlElementController`
|
|
330
388
|
|
|
331
389
|
This method returns an element addressed by `index`. If failed `null` is returned.
|
|
332
390
|
|
|
333
|
-
##### **addItem(obj)**
|
|
391
|
+
##### **addItem(obj)** => `index`
|
|
334
392
|
|
|
335
393
|
This method adds an element to a list members. If succeed an index of the element is returned.
|
|
336
394
|
|
|
337
|
-
##### **setItem(index, obj)**
|
|
395
|
+
##### **setItem(index, obj)** => `boolean`
|
|
338
396
|
|
|
339
397
|
This method replaces an element addressed by `index` with a new element. If succeed `true` is returned.
|
|
340
398
|
|
|
341
|
-
##### **insItem(index, obj)**
|
|
399
|
+
##### **insItem(index, obj)** => `boolean`
|
|
342
400
|
|
|
343
401
|
This method inserts an element in the position addressed by `index`. If succeed `true` is returned.
|
|
344
402
|
|
|
345
|
-
##### **delItem(index)**
|
|
403
|
+
##### **delItem(index)** => `boolean`
|
|
346
404
|
|
|
347
405
|
This method deletes an element addressed by `index`. If succeed `true` is returned.
|
|
348
406
|
|
|
349
|
-
##### **loadItems(items, options)**
|
|
407
|
+
##### **loadItems(items, options)** => `number`
|
|
350
408
|
|
|
351
409
|
This method loaded a list of elements listed by `items` and returns a quantity of a successfully added elements.
|
|
352
410
|
|
|
@@ -391,7 +449,7 @@ The class constructor receives an arguments listed below:
|
|
|
391
449
|
|`object`|`object`|---|a host object for the document content.|
|
|
392
450
|
|`options`|`object`|---|an options settings.|
|
|
393
451
|
|
|
394
|
-
|
|
452
|
+
###### `options` parameter
|
|
395
453
|
|
|
396
454
|
The `options` structure is listed below:
|
|
397
455
|
|
|
@@ -399,6 +457,10 @@ The `options` structure is listed below:
|
|
|
399
457
|
|:---|---|---:|:---|
|
|
400
458
|
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (see description for `XML_DEF_PARSE_OPTIONS`)|
|
|
401
459
|
|
|
460
|
+
##### exceptions
|
|
461
|
+
|
|
462
|
+
If `object` parameter is not a type of `object` or not given a `TypeError` thrown.
|
|
463
|
+
|
|
402
464
|
#### class properties
|
|
403
465
|
|
|
404
466
|
|property name|property type|read only|description|
|
|
@@ -408,7 +470,7 @@ The `options` structure is listed below:
|
|
|
408
470
|
|
|
409
471
|
#### class methods (*special*)
|
|
410
472
|
|
|
411
|
-
##### **init()**
|
|
473
|
+
##### **init()** => `boolean`
|
|
412
474
|
|
|
413
475
|
This method initializes an element with a default values.
|
|
414
476
|
|
|
@@ -429,7 +491,7 @@ The class constructor receives an arguments listed below:
|
|
|
429
491
|
|`object`|`object`|---|a host object for the document content|
|
|
430
492
|
|`options`|`object`|---|an options settings|
|
|
431
493
|
|
|
432
|
-
|
|
494
|
+
###### `options` parameter
|
|
433
495
|
|
|
434
496
|
The `options` structure is listed below:
|
|
435
497
|
|
|
@@ -469,7 +531,7 @@ The class constructor creates a new instance of the class.
|
|
|
469
531
|
|
|
470
532
|
The class constructor receives an `options` parameter as its argument.
|
|
471
533
|
|
|
472
|
-
|
|
534
|
+
###### `options` parameter
|
|
473
535
|
|
|
474
536
|
The `options` structure is listed below:
|
|
475
537
|
|
|
@@ -489,11 +551,11 @@ The `options` structure is listed below:
|
|
|
489
551
|
|
|
490
552
|
#### class methods
|
|
491
553
|
|
|
492
|
-
##### **clear()**
|
|
554
|
+
##### **clear()** => `void`
|
|
493
555
|
|
|
494
556
|
This method clears a document content.
|
|
495
557
|
|
|
496
|
-
##### **saveToXMLString()**
|
|
558
|
+
##### **saveToXMLString()** => `string`
|
|
497
559
|
|
|
498
560
|
This method returns a document content as a string.
|
|
499
561
|
|
|
@@ -501,7 +563,7 @@ This method returns a document content as a string.
|
|
|
501
563
|
|
|
502
564
|
This method saves a document content into a file addressed by `src`.
|
|
503
565
|
|
|
504
|
-
##### **loadFromXMLString(str)**
|
|
566
|
+
##### **loadFromXMLString(str)** => `boolean`
|
|
505
567
|
|
|
506
568
|
This method loads a document content from a string given by `str`.
|
|
507
569
|
|