@cntwg/xml-lib-js 0.0.16
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 +140 -0
- package/LICENSE +9 -0
- package/README.md +32 -0
- package/doc/xmldoc-lib.md +455 -0
- package/index.js +31 -0
- package/lib/xmldoc-lib.js +1025 -0
- package/package.json +35 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#### *v0.0.16*
|
|
2
|
+
|
|
3
|
+
Pre-release version.
|
|
4
|
+
|
|
5
|
+
> - `xmldoc-lib.md` updated;
|
|
6
|
+
> - removed method `init()` from `TXmlContentRootElement` class;
|
|
7
|
+
> - some fixes in `xmldoc-lib.js` module.
|
|
8
|
+
|
|
9
|
+
#### *v0.0.15*
|
|
10
|
+
|
|
11
|
+
Pre-release version.
|
|
12
|
+
|
|
13
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.1.2;
|
|
14
|
+
> - updated dependency on `@ygracs/xobj-lib-js` module to v0.0.13;
|
|
15
|
+
|
|
16
|
+
#### *v0.0.14*
|
|
17
|
+
|
|
18
|
+
Pre-release version.
|
|
19
|
+
|
|
20
|
+
> - updated dependency on `@ygracs/bsfoc-lib-js` module to v0.1.1;
|
|
21
|
+
> - updated dependency on `@ygracs/xobj-lib-js` module to v0.0.12;
|
|
22
|
+
|
|
23
|
+
#### *v0.0.13*
|
|
24
|
+
|
|
25
|
+
Pre-release version.
|
|
26
|
+
|
|
27
|
+
> - `xmldoc-lib.md` updated;
|
|
28
|
+
> - added method `hasAttribute()` to `TXmlAttributesMapper` class;
|
|
29
|
+
> - added method `hasAttribute()` to `TXmlElementController` class;
|
|
30
|
+
> - added method `delChild()` to `TXmlElementController` class;
|
|
31
|
+
> - some fixes in `xmldoc-lib.js` module.
|
|
32
|
+
|
|
33
|
+
#### *v0.0.12*
|
|
34
|
+
|
|
35
|
+
Pre-release version.
|
|
36
|
+
|
|
37
|
+
> - `xmldoc-lib.md` updated;
|
|
38
|
+
> - some fixes in `xmldoc-lib.js` module.
|
|
39
|
+
|
|
40
|
+
#### *v0.0.11*
|
|
41
|
+
|
|
42
|
+
Pre-release version.
|
|
43
|
+
|
|
44
|
+
> - `xmldoc-lib.md` updated;
|
|
45
|
+
> - some fixes in `xmldoc-lib.js` module;
|
|
46
|
+
> - added method `clear()` to `TXmlAttributesMapper` class;
|
|
47
|
+
> - added method `getTextValue()` to `TXmlElementController` class;
|
|
48
|
+
> - added method `setTextValue()` to `TXmlElementController` class;
|
|
49
|
+
> - added property `maxIndex` to `TXmlElementsListController` class;
|
|
50
|
+
> - change to `TXmlContentRootElement` constructor: `name` param was excluded.
|
|
51
|
+
|
|
52
|
+
#### *v0.0.10*
|
|
53
|
+
|
|
54
|
+
Pre-release version.
|
|
55
|
+
|
|
56
|
+
> - switch dependency from `@cntwg/bsfoc-lib-js` module to `@ygracs/bsfoc-lib-js` module;
|
|
57
|
+
> - updated dependency on `@ygracs/xml-js6` module to v0.0.3b;
|
|
58
|
+
> - added dependency on `@ygracs/xobj-lib-js` module;
|
|
59
|
+
> - deprecate `$module/lib/xObj-lib.js` module;
|
|
60
|
+
> - `xObj-lib.md` deprecated.
|
|
61
|
+
|
|
62
|
+
#### *v0.0.9*
|
|
63
|
+
|
|
64
|
+
Pre-release version.
|
|
65
|
+
|
|
66
|
+
> - updated dependency on `@cntwg/bsfoc-lib-js` module to v0.0.11;
|
|
67
|
+
> - some fixes in `xmldoc-lib.js` module;
|
|
68
|
+
> - some fixes in `xObj-lib.js` module.
|
|
69
|
+
|
|
70
|
+
#### *v0.0.8*
|
|
71
|
+
|
|
72
|
+
Pre-release version.
|
|
73
|
+
|
|
74
|
+
> - `xmldoc-lib.md` updated;
|
|
75
|
+
> - `xObj-lib.md` updated;
|
|
76
|
+
> - updated dependency on `@cntwg/bsfoc-lib-js` module to v0.0.8;
|
|
77
|
+
> - some fixes in `xmldoc-lib.js` module;
|
|
78
|
+
> - added special static method `__unwrap()` to `TXmlContentRootElement` class.
|
|
79
|
+
|
|
80
|
+
#### *v0.0.7*
|
|
81
|
+
|
|
82
|
+
Pre-release version.
|
|
83
|
+
|
|
84
|
+
> - `xmldoc-lib.md` updated;
|
|
85
|
+
> - `xObj-lib.md` updated;
|
|
86
|
+
> - added function `getXObjAttributes()` in `xObj-lib.js` module;
|
|
87
|
+
> - fixed some errors in `xmldoc-lib.js` module;
|
|
88
|
+
> - added method `addChild()` to `TXmlElementController` class;
|
|
89
|
+
> - added special method `_addChildRaw()` to `TXmlElementController` class;
|
|
90
|
+
> - add tests of 'TXmlElementController' class for `xmldoc-lib.js` module;
|
|
91
|
+
> - add tests of 'TXmlElementsListController' class for `xmldoc-lib.js` module;
|
|
92
|
+
> - add tests of 'TXmlContentContainer' class for `xmldoc-lib.js` module.
|
|
93
|
+
|
|
94
|
+
#### *v0.0.6*
|
|
95
|
+
|
|
96
|
+
Pre-release version.
|
|
97
|
+
|
|
98
|
+
> - `xObj-lib.md` updated;
|
|
99
|
+
> - updated dependency on `@cntwg/bsfoc-lib-js` module to v0.0.7;
|
|
100
|
+
> - updated dependency on `@ygracs/xml-js6` module to v0.0.3;
|
|
101
|
+
> - fixed some errors in `xObj-lib.js` module;
|
|
102
|
+
> - added function `writeXObjParamEx()` in `xObj-lib.js` module;
|
|
103
|
+
> - removed function `writeXObjParamAsStr()` from `xObj-lib.js` module;
|
|
104
|
+
> - added function `writeXObjAttrEx()` in `xObj-lib.js` module;
|
|
105
|
+
> - removed function `writeXObjAttrAsStr()` from `xObj-lib.js` module;
|
|
106
|
+
> - added function `addXObjElement()` in `xObj-lib.js` module;
|
|
107
|
+
> - added function `deleteXObjElement()` in `xObj-lib.js` module;
|
|
108
|
+
> - added function `deleteXObjElementEx()` in `xObj-lib.js` module;
|
|
109
|
+
> - added function `renameXObjElement()` in `xObj-lib.js` module;
|
|
110
|
+
> - add tests for `xObj-lib.js` module.
|
|
111
|
+
|
|
112
|
+
#### *v0.0.5*
|
|
113
|
+
|
|
114
|
+
Pre-release version.
|
|
115
|
+
|
|
116
|
+
> - `README.md` updated;
|
|
117
|
+
> - `xmldoc-lib.md` updated;
|
|
118
|
+
> - removed method `_unwrap()` from class `TXmlElementController`;
|
|
119
|
+
> - added method `saveToFileSync()` to class `TXmlContentContainer`;
|
|
120
|
+
> - added method `loadFromFileSync()` to class `TXmlContentContainer`.
|
|
121
|
+
|
|
122
|
+
#### *v0.0.4*
|
|
123
|
+
|
|
124
|
+
Pre-release version.
|
|
125
|
+
|
|
126
|
+
> - `xmldoc-lib.md` updated.
|
|
127
|
+
|
|
128
|
+
#### *v0.0.3*
|
|
129
|
+
|
|
130
|
+
Pre-release version.
|
|
131
|
+
|
|
132
|
+
> - `README.md` updated;
|
|
133
|
+
> - updated dependency on `@cntwg/bsfoc-lib-js` module to v0.0.6;
|
|
134
|
+
> - added dependency on `@ygracs/xml-js6` module;
|
|
135
|
+
> - include `$module/lib/xmldoc-lib.js` module;
|
|
136
|
+
> - license included.
|
|
137
|
+
|
|
138
|
+
#### *v0.0.1-v0.0.2*
|
|
139
|
+
|
|
140
|
+
Pre-release version.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-2022 Yuri Grachev
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|***rev.*:**|0.1.2|
|
|
2
|
+
|:---|---:|
|
|
3
|
+
|***date***:|2022-09-06|
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
This module provide a base functionality for handling an XML-documents.
|
|
8
|
+
|
|
9
|
+
### 1. xObj-manipulator
|
|
10
|
+
|
|
11
|
+
xObj-manipulator is a set of functions (see docs for [`@ygracs/xobj-lib-js` module](https://gitlab.com/ygracs/xobj-lib-js)).
|
|
12
|
+
|
|
13
|
+
### 2. a set of XML-document constants and components
|
|
14
|
+
|
|
15
|
+
- constants:
|
|
16
|
+
|
|
17
|
+
+ `XML_DEF_ROOT_ETAG_NAME`;
|
|
18
|
+
+ `XML_DEF_PARSE_OPTIONS`;
|
|
19
|
+
+ `DEF_XML_ROOT_ETAG_NAME` (*will deprecate*);
|
|
20
|
+
+ `DEF_XML_PARSE_OPTIONS` (*will deprecate*).
|
|
21
|
+
|
|
22
|
+
- classes:
|
|
23
|
+
|
|
24
|
+
+ `TXmlAttributesMapper`;
|
|
25
|
+
+ `TXmlElementController`;
|
|
26
|
+
+ `TXmlElementsListController`;
|
|
27
|
+
+ `TXmlContentParseOptions`;
|
|
28
|
+
+ `TXmlContentDeclaration`;
|
|
29
|
+
+ `TXmlContentRootElement`;
|
|
30
|
+
+ `TXmlContentContainer`.
|
|
31
|
+
|
|
32
|
+
For more read the `xmldoc-lib.md` in the project `doc` directory.
|
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
>|***rev.*:**|0.1.18|
|
|
2
|
+
>|:---|---:|
|
|
3
|
+
>|date:|2022-09-06|
|
|
4
|
+
|
|
5
|
+
## Intoduction
|
|
6
|
+
|
|
7
|
+
This paper describes a constants and an object classes provided by `xmldoc-lib.js` module.
|
|
8
|
+
|
|
9
|
+
## Module constants
|
|
10
|
+
|
|
11
|
+
### **DEF\_XML\_PARSE_OPTIONS** or **XML\_DEF\_PARSE_OPTIONS**
|
|
12
|
+
|
|
13
|
+
This constant object provided by the module contains a default settings of options for XML-parser module used within.
|
|
14
|
+
|
|
15
|
+
The settings listed in the table below:
|
|
16
|
+
|
|
17
|
+
|name|type|value|
|
|
18
|
+
|:---|---|:---|
|
|
19
|
+
|`compact`|`boolean`|`true`|
|
|
20
|
+
|`declarationKey`|`string`|`__decl`|
|
|
21
|
+
|`attributesKey`|`string`|`__attr`|
|
|
22
|
+
|`textKey`|`string`|`__text`|
|
|
23
|
+
|`commentKey`|`string`|`__note`|
|
|
24
|
+
|`cdataKey`|`string`|`__cdata`|
|
|
25
|
+
|`nameKey`|`string`|`__name`|
|
|
26
|
+
|`typeKey`|`string`|`__type`|
|
|
27
|
+
|`parentKey`|`string`|`parent`|
|
|
28
|
+
|`elementsKey`|`string`|`items`|
|
|
29
|
+
|`ignoreDeclaration`|`boolean`|`false`|
|
|
30
|
+
|`ignoreDocType`|`boolean`|`false`|
|
|
31
|
+
|`ignoreInstractions`|`boolean`|`false`|
|
|
32
|
+
|`ignoreText`|`boolean`|`false`|
|
|
33
|
+
|`ignoreComments`|`boolean`|`false`|
|
|
34
|
+
|`ignoreCData`|`boolean`|`false`|
|
|
35
|
+
|`fullTagEmptyElement`|`boolean`|`true`|
|
|
36
|
+
|`addParent`|`boolean`|`false`|
|
|
37
|
+
|`trim`|`boolean`|`true`|
|
|
38
|
+
|`spaces`|`number`|`2`|
|
|
39
|
+
|
|
40
|
+
### **DEF\_XML\_ROOT\_ETAG_NAME** or **XML\_DEF\_ROOT\_ETAG_NAME**
|
|
41
|
+
|
|
42
|
+
This constant defines a default value for naming the root element for XML-document. Its value is `root`.
|
|
43
|
+
|
|
44
|
+
## Module classes
|
|
45
|
+
|
|
46
|
+
### **TXmlContentParseOptions**
|
|
47
|
+
|
|
48
|
+
This class implements an interface for handling XML-parse options.
|
|
49
|
+
|
|
50
|
+
#### class constructor
|
|
51
|
+
|
|
52
|
+
The class constructor creates a new instance of the class. It receives arguments listed below:
|
|
53
|
+
|
|
54
|
+
|name|type|default value|description|
|
|
55
|
+
|:---|---|---:|:---|
|
|
56
|
+
|`object`|---|---|a host object.|
|
|
57
|
+
|`options`|`object`|---|an options settings.|
|
|
58
|
+
|
|
59
|
+
#### class properties
|
|
60
|
+
|
|
61
|
+
The table below describes a properties of a `TXmlContentParseOptions` class:
|
|
62
|
+
|
|
63
|
+
|name|read only|description|
|
|
64
|
+
|:---|---|:---|
|
|
65
|
+
|settings|yes|presents a current options|
|
|
66
|
+
|xml2js|yes|returns an options for an XML-to-JS converter|
|
|
67
|
+
|js2xml|yes|returns an options for an JS-to-XML converter|
|
|
68
|
+
|
|
69
|
+
#### class methods (*static*)
|
|
70
|
+
|
|
71
|
+
##### **createNewOptionsSet(obj)**
|
|
72
|
+
|
|
73
|
+
This method transforms a given object to a set of accepted parser options.
|
|
74
|
+
|
|
75
|
+
### **TXmlAttributesMapper**
|
|
76
|
+
|
|
77
|
+
This class implements a proxy interface for handling attributes of an element.
|
|
78
|
+
|
|
79
|
+
#### class constructor
|
|
80
|
+
|
|
81
|
+
The class constructor creates a new instance of the class. It receives arguments listed below:
|
|
82
|
+
|
|
83
|
+
|name|type|default value|description|
|
|
84
|
+
|:---|---|---:|:---|
|
|
85
|
+
|`object`|---|---|a host object that holds an attributes|
|
|
86
|
+
|`options`|`object`|---|an options settings|
|
|
87
|
+
|
|
88
|
+
The `options` structure is listed below:
|
|
89
|
+
|
|
90
|
+
|option name|value type|default value|description|
|
|
91
|
+
|:---|---|---:|:---|
|
|
92
|
+
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (*see description for `XML_DEF_PARSE_OPTIONS`*)|
|
|
93
|
+
|
|
94
|
+
#### class properties
|
|
95
|
+
|
|
96
|
+
|name|read only|description|
|
|
97
|
+
|:---|---|:---|
|
|
98
|
+
|`entries`|yes|returns array of entries for all existing attributes|
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
#### class methods
|
|
102
|
+
|
|
103
|
+
##### **hasAttribute(name)**
|
|
104
|
+
|
|
105
|
+
This method checks whether or not an attribute addressed by a `name` exists. If attribute exists, 'true' is returned.
|
|
106
|
+
|
|
107
|
+
##### **getAttribute(name)**
|
|
108
|
+
|
|
109
|
+
This method returns an attribute value addressed by a `name`. If attribute is not exists the empty string is returned.
|
|
110
|
+
|
|
111
|
+
##### **setAttribute(name, value)**
|
|
112
|
+
|
|
113
|
+
This method sets an attribute value addressed by a `name` and return `true` if succeed.
|
|
114
|
+
|
|
115
|
+
##### **delAttribute(name)**
|
|
116
|
+
|
|
117
|
+
This method clears an attribute value addressed by a `name`.
|
|
118
|
+
|
|
119
|
+
##### **clear()**
|
|
120
|
+
|
|
121
|
+
This method clears all attributes.
|
|
122
|
+
|
|
123
|
+
### **TXmlElementController**
|
|
124
|
+
|
|
125
|
+
This class implements a proxy interface for an element.
|
|
126
|
+
|
|
127
|
+
#### class constructor
|
|
128
|
+
|
|
129
|
+
The class constructor creates a new instance of the class. It receives an arguments listed below:
|
|
130
|
+
|
|
131
|
+
|name|type|default value|description|
|
|
132
|
+
|:---|---|---:|:---|
|
|
133
|
+
|`object`|---|---|a host object|
|
|
134
|
+
|`options`|`object`|---|an options settings|
|
|
135
|
+
|
|
136
|
+
The `options` structure is listed below:
|
|
137
|
+
|
|
138
|
+
|option name|value type|default value|description|
|
|
139
|
+
|:---|---|---:|:---|
|
|
140
|
+
|`proxyModeEnable`|`boolean`|`false`|<*reserved*>|
|
|
141
|
+
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (see description for `XML_DEF_PARSE_OPTIONS`)|
|
|
142
|
+
|
|
143
|
+
#### class properties
|
|
144
|
+
|
|
145
|
+
|property name|read only|description|
|
|
146
|
+
|:---|---|:---|
|
|
147
|
+
|`attributes`|yes|returns an attributes of the element|
|
|
148
|
+
|`name`|yes|returns a tag name of the element|
|
|
149
|
+
|`textValue`|no|represents a value of the element|
|
|
150
|
+
|
|
151
|
+
#### class methods
|
|
152
|
+
|
|
153
|
+
##### **hasAttribute(name)**
|
|
154
|
+
|
|
155
|
+
This method checks whether or not an attribute addressed by a `name` exists. If attribute exists, 'true' is returned.
|
|
156
|
+
|
|
157
|
+
##### **getAttribute(name)**
|
|
158
|
+
|
|
159
|
+
This method returns an attribute value addressed by a `name`. If attribute is not exists the empty string is returned.
|
|
160
|
+
|
|
161
|
+
##### **setAttribute(name, value)**
|
|
162
|
+
|
|
163
|
+
This method sets an attribute value addressed by a `name` and return `true` if succeed.
|
|
164
|
+
|
|
165
|
+
##### **delAttribute(name)**
|
|
166
|
+
|
|
167
|
+
This method clears an attribute value addressed by a `name`.
|
|
168
|
+
|
|
169
|
+
##### **getTextValue()**
|
|
170
|
+
|
|
171
|
+
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.
|
|
172
|
+
|
|
173
|
+
##### **setTextValue(value)**
|
|
174
|
+
|
|
175
|
+
This method sets the value of a `textValue` property and its `lang` attribute and if succeed returns `true`.
|
|
176
|
+
|
|
177
|
+
The method received value that can be a string or an array. If value is an array it must be in the following format:
|
|
178
|
+
`[ <textValue> ]`
|
|
179
|
+
or
|
|
180
|
+
`[ <lang>, <textValue> ]`.
|
|
181
|
+
|
|
182
|
+
##### **getChild(name)**
|
|
183
|
+
|
|
184
|
+
This method returns a child element addressed by `name`.
|
|
185
|
+
|
|
186
|
+
##### **addChild(name)**
|
|
187
|
+
|
|
188
|
+
This method adds an element as a child element addressed by a `name`.
|
|
189
|
+
|
|
190
|
+
##### **delChild(name)**
|
|
191
|
+
|
|
192
|
+
This method deletes a child element addressed by a `name`.
|
|
193
|
+
|
|
194
|
+
> Warning: method not fully implemented. not used for list like elements.
|
|
195
|
+
|
|
196
|
+
##### **clear()**
|
|
197
|
+
|
|
198
|
+
This method clears an element content.
|
|
199
|
+
|
|
200
|
+
#### class methods (*special*)
|
|
201
|
+
|
|
202
|
+
##### **_getChildRaw(name)**
|
|
203
|
+
|
|
204
|
+
This method returns a child element addressed by `name` as object.
|
|
205
|
+
|
|
206
|
+
##### **_addChildRaw(name)**
|
|
207
|
+
|
|
208
|
+
This method adds an element as a child element addressed by `name`.
|
|
209
|
+
|
|
210
|
+
##### **_setChildRaw(name, obj)**
|
|
211
|
+
|
|
212
|
+
This method inserts a given object as a child element addressed by `name`.
|
|
213
|
+
|
|
214
|
+
#### class methods (*static*)
|
|
215
|
+
|
|
216
|
+
##### **__unwrap(item)**
|
|
217
|
+
|
|
218
|
+
This method returns a host for an element as an object. If failed `null` is returned.
|
|
219
|
+
|
|
220
|
+
##### **clear(item)**
|
|
221
|
+
|
|
222
|
+
This method clears an `item` content.
|
|
223
|
+
|
|
224
|
+
### **TXmlElementsListController**
|
|
225
|
+
|
|
226
|
+
This class implements a proxy interface for a list of elements.
|
|
227
|
+
|
|
228
|
+
#### class constructor
|
|
229
|
+
|
|
230
|
+
The class constructor creates a new instance of the class. It receives arguments listed below:
|
|
231
|
+
|
|
232
|
+
|name|type|default value|description|
|
|
233
|
+
|:---|---|---:|:---|
|
|
234
|
+
|`object`|---|---|a host object of an array type.|
|
|
235
|
+
|`options`|`object`|---|an options settings.|
|
|
236
|
+
|
|
237
|
+
The `options` structure is listed below:
|
|
238
|
+
|
|
239
|
+
|option name|value type|default value|description|
|
|
240
|
+
|:---|---|---:|:---|
|
|
241
|
+
|`proxyModeEnable`|`boolean`|`false`|<*reserved*>|
|
|
242
|
+
|`isNullItemsAllowed`|`boolean`|`false`|<*reserved*>|
|
|
243
|
+
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (see description for `XML_DEF_PARSE_OPTIONS`)|
|
|
244
|
+
|
|
245
|
+
#### class properties
|
|
246
|
+
|
|
247
|
+
|property name|property type|read only|description|
|
|
248
|
+
|:---|---|:---|
|
|
249
|
+
|`count`|`number`|yes|returns a quantity of the elements|
|
|
250
|
+
|`size`|`number`|yes|returns a quantity of the elements|
|
|
251
|
+
|`maxIndex`|`index`|yes|returns a last possible index of the elements|
|
|
252
|
+
|`isNullItemsAllowed`|`boolean`|yes|indicates whether a list may be filled with the null-elements or not|
|
|
253
|
+
|
|
254
|
+
#### class methods
|
|
255
|
+
|
|
256
|
+
##### **clear()**
|
|
257
|
+
|
|
258
|
+
This method clears a list.
|
|
259
|
+
|
|
260
|
+
##### **isEmpty()**
|
|
261
|
+
|
|
262
|
+
This method returns `true` if a list has no elements and `false` otherwise.
|
|
263
|
+
|
|
264
|
+
##### **isNotEmpty()**
|
|
265
|
+
|
|
266
|
+
This method returns `true` if a list contains at least one element and `false` otherwise.
|
|
267
|
+
|
|
268
|
+
##### **chkIndex(index)**
|
|
269
|
+
|
|
270
|
+
This method checks if a given index fits a range of elements within the list. If so `true` is returned.
|
|
271
|
+
|
|
272
|
+
##### **isValidItem(obj)**
|
|
273
|
+
|
|
274
|
+
This method checks whether or not a given element is valid.
|
|
275
|
+
|
|
276
|
+
##### **getItem(index)**
|
|
277
|
+
|
|
278
|
+
This method returns an element addressed by `index`. If failed `null` is returned.
|
|
279
|
+
|
|
280
|
+
##### **addItem(obj)**
|
|
281
|
+
|
|
282
|
+
This method adds an element to a list members. If succeed an index of the element is returned.
|
|
283
|
+
|
|
284
|
+
##### **setItem(index, obj)**
|
|
285
|
+
|
|
286
|
+
This method replaces an element addressed by `index` with a new element. If succeed `true` is returned.
|
|
287
|
+
|
|
288
|
+
##### **insItem(index, obj)**
|
|
289
|
+
|
|
290
|
+
This method inserts an element in the position addressed by `index`. If succeed `true` is returned.
|
|
291
|
+
|
|
292
|
+
##### **delItem(index)**
|
|
293
|
+
|
|
294
|
+
This method deletes an element addressed by `index`. If succeed `true` is returned.
|
|
295
|
+
|
|
296
|
+
##### **loadItems(items, options)**
|
|
297
|
+
|
|
298
|
+
This method loaded a list of elements listed by `items` and returns a quantity of a successfuly added elements.
|
|
299
|
+
|
|
300
|
+
#### class methods (*special*)
|
|
301
|
+
|
|
302
|
+
##### **_getItemRaw(name)**
|
|
303
|
+
|
|
304
|
+
This method returns an element addressed by `index` as object. If failed `null` is returned.
|
|
305
|
+
|
|
306
|
+
##### **_addItemRaw(obj)**
|
|
307
|
+
|
|
308
|
+
This method adds an element to a list members as object. If succeed an index of the element is returned.
|
|
309
|
+
|
|
310
|
+
##### **_setItemRaw(index, obj)**
|
|
311
|
+
|
|
312
|
+
This method replaces an element addressed by `index` with a new element which is saved as raw object. If succeed `true` is returned.
|
|
313
|
+
|
|
314
|
+
##### **_insItemRaw(index, obj)**
|
|
315
|
+
|
|
316
|
+
This method inserts an element as a raw object in the position addressed by `index`. If succeed `true` is returned.
|
|
317
|
+
|
|
318
|
+
### **TXmlContentDeclaration**
|
|
319
|
+
|
|
320
|
+
This class implements a proxy interface for a document declaration element.
|
|
321
|
+
|
|
322
|
+
#### class constructor
|
|
323
|
+
|
|
324
|
+
The class constructor creates a new instance of the class. It receives arguments listed below:
|
|
325
|
+
|
|
326
|
+
|name|type|default value|description|
|
|
327
|
+
|:---|---|---:|:---|
|
|
328
|
+
|`object`|`object`|---|a host object for the document content.|
|
|
329
|
+
|`options`|`object`|---|an options settings.|
|
|
330
|
+
|
|
331
|
+
The `options` structure is listed below:
|
|
332
|
+
|
|
333
|
+
|option name|value type|default value|description|
|
|
334
|
+
|:---|---|---:|:---|
|
|
335
|
+
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (see description for `XML_DEF_PARSE_OPTIONS`)|
|
|
336
|
+
|
|
337
|
+
#### class properties
|
|
338
|
+
|
|
339
|
+
|property name|property type|read only|description|
|
|
340
|
+
|:---|---|:---|
|
|
341
|
+
|`version`|`string`|no|returns a version of a XML|
|
|
342
|
+
|`encoding`|`string`|no|returns an encodings used by a document|
|
|
343
|
+
|
|
344
|
+
#### class methods (*special*)
|
|
345
|
+
|
|
346
|
+
##### **init()**
|
|
347
|
+
|
|
348
|
+
This method initializes element with a default values.
|
|
349
|
+
|
|
350
|
+
### **TXmlContentRootElement**
|
|
351
|
+
|
|
352
|
+
This class extends functionality of a `TXmlElementController` class.
|
|
353
|
+
|
|
354
|
+
#### class constructor
|
|
355
|
+
|
|
356
|
+
The class constructor creates a new instance of the class. It receives arguments listed below:
|
|
357
|
+
|
|
358
|
+
|name|type|default value|description|
|
|
359
|
+
|:---|---|---:|:---|
|
|
360
|
+
|`object`|`object`|---|a host object for the document content|
|
|
361
|
+
|`options`|`object`|---|an options settings|
|
|
362
|
+
|
|
363
|
+
The `options` structure is listed below:
|
|
364
|
+
|
|
365
|
+
|option name|value type|default value|description|
|
|
366
|
+
|:---|---|---:|:---|
|
|
367
|
+
|`rootETagName`|`string`|`root`|contains a the name of a tag that represents a root element|
|
|
368
|
+
|`autoBindRoot`|`boolean`|`true`|<*reserved*>|
|
|
369
|
+
|`proxyModeEnable`|`boolean`|`false`|<*reserved*>|
|
|
370
|
+
|`isNullItemsAllowed`|`boolean`|`false`|<*reserved*>|
|
|
371
|
+
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (see description for `XML_DEF_PARSE_OPTIONS`)|
|
|
372
|
+
|
|
373
|
+
#### class properties
|
|
374
|
+
|
|
375
|
+
|name|read only|description|
|
|
376
|
+
|:---|---|:---|
|
|
377
|
+
|tagName|no||
|
|
378
|
+
|
|
379
|
+
#### class methods (*static*)
|
|
380
|
+
|
|
381
|
+
##### **__unwrap(item\[, options])**
|
|
382
|
+
|
|
383
|
+
This method returns a host for an element as an object. If failed `null` is returned.
|
|
384
|
+
|
|
385
|
+
The `options` parameter, if given, change a behavoir for the method. If set to 'true' the given instance checks aganst inheritance from a `TXmlContentRootElement`, if else, from a `TXmlElementController` class.
|
|
386
|
+
|
|
387
|
+
#### class methods (*special*)
|
|
388
|
+
|
|
389
|
+
### **TXmlContentContainer**
|
|
390
|
+
|
|
391
|
+
This class implements a proxy interface for manipulate a content of a document.
|
|
392
|
+
|
|
393
|
+
#### class constructor
|
|
394
|
+
|
|
395
|
+
The class constructor creates a new instance of the class. It receives an `options` parameter as its argument.
|
|
396
|
+
|
|
397
|
+
The `options` structure is listed below:
|
|
398
|
+
|
|
399
|
+
|option name|value type|default value|description|
|
|
400
|
+
|:---|---|---:|:---|
|
|
401
|
+
|`rootETagName`|`string`|`root`|contains a the name of a tag that represents a root element|
|
|
402
|
+
|`autoBindRoot`|`boolean`|`true`|<*reserved*>|
|
|
403
|
+
|`proxyModeEnable`|`boolean`|`false`|<*reserved*>|
|
|
404
|
+
|`isNullItemsAllowed`|`boolean`|`false`|<*reserved*>|
|
|
405
|
+
|`parseOptions`|`object`|`EMPTY_OBJECT`|contains a XML-parse options (see description for `XML_DEF_PARSE_OPTIONS`)|
|
|
406
|
+
|
|
407
|
+
#### class properties
|
|
408
|
+
|
|
409
|
+
|property name|read only|description|
|
|
410
|
+
|:---|---|:---|
|
|
411
|
+
|rootElement|yes|returns a document root element|
|
|
412
|
+
|
|
413
|
+
#### class methods
|
|
414
|
+
|
|
415
|
+
##### **clear()**
|
|
416
|
+
|
|
417
|
+
This method clears a document content.
|
|
418
|
+
|
|
419
|
+
##### **saveToXMLString()**
|
|
420
|
+
|
|
421
|
+
This method returns a document content as a string.
|
|
422
|
+
|
|
423
|
+
##### **saveToFile(src)**
|
|
424
|
+
|
|
425
|
+
This method saves a document content into a file addressed by `src`.
|
|
426
|
+
|
|
427
|
+
> This is `async` method.
|
|
428
|
+
|
|
429
|
+
##### **saveToFileSync(src)**
|
|
430
|
+
|
|
431
|
+
This method saves a document content into a file addressed by `src`.
|
|
432
|
+
|
|
433
|
+
##### **loadFromXMLString(str)**
|
|
434
|
+
|
|
435
|
+
This method loads a document content from a string given by `str`.
|
|
436
|
+
|
|
437
|
+
##### **loadFromFile(src)**
|
|
438
|
+
|
|
439
|
+
This method loads a document content from a file addressed by `src`.
|
|
440
|
+
|
|
441
|
+
> This is `async` method.
|
|
442
|
+
|
|
443
|
+
##### **loadFromFileSync(src)**
|
|
444
|
+
|
|
445
|
+
This method loads a document content from a file addressed by `src`.
|
|
446
|
+
|
|
447
|
+
#### class methods (*special*)
|
|
448
|
+
|
|
449
|
+
##### **asJSON()**
|
|
450
|
+
|
|
451
|
+
This method returns a document content as a string in the JSON-format.
|
|
452
|
+
|
|
453
|
+
##### **_bindContent(obj\[, options])**
|
|
454
|
+
|
|
455
|
+
This method binds a given object as a document content.
|
package/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// [v0.1.007-20220722]
|
|
2
|
+
|
|
3
|
+
// === module init block ===
|
|
4
|
+
|
|
5
|
+
const xObj = require('@ygracs/xobj-lib-js');
|
|
6
|
+
const xmldoc = require('./lib/xmldoc-lib.js');
|
|
7
|
+
|
|
8
|
+
// === module extra block (helper functions) ===
|
|
9
|
+
|
|
10
|
+
// === module main block ===
|
|
11
|
+
|
|
12
|
+
// === module exports block ===
|
|
13
|
+
|
|
14
|
+
exports.xObj = xObj;
|
|
15
|
+
|
|
16
|
+
// will deprecate
|
|
17
|
+
exports.DEF_XML_PARSE_OPTIONS = xmldoc.DEF_XML_PARSE_OPTIONS;
|
|
18
|
+
// will deprecate
|
|
19
|
+
exports.DEF_XML_ROOT_ETAG_NAME = xmldoc.DEF_XML_ROOT_ETAG_NAME;
|
|
20
|
+
|
|
21
|
+
exports.XML_DEF_PARSE_OPTIONS = xmldoc.XML_DEF_PARSE_OPTIONS;
|
|
22
|
+
exports.XML_DEF_ROOT_ETAG_NAME = xmldoc.XML_DEF_ROOT_ETAG_NAME;
|
|
23
|
+
|
|
24
|
+
exports.TXmlContentParseOptions = xmldoc.TXmlContentParseOptions;
|
|
25
|
+
|
|
26
|
+
exports.TXmlAttributesMapper = xmldoc.TXmlAttributesMapper;
|
|
27
|
+
exports.TXmlElementController = xmldoc.TXmlElementController;
|
|
28
|
+
exports.TXmlElementsListController = xmldoc.TXmlElementsListController;
|
|
29
|
+
exports.TXmlContentDeclaration = xmldoc.TXmlContentDeclaration;
|
|
30
|
+
exports.TXmlContentRootElement = xmldoc.TXmlContentRootElement;
|
|
31
|
+
exports.TXmlContentContainer = xmldoc.TXmlContentContainer;
|