fast-xml-parser 3.20.3 → 4.0.0-beta.2
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 +421 -0
- package/README.md +79 -267
- package/package.json +9 -38
- package/{cli.js → src/cli/cli.js} +16 -24
- package/src/cli/man.js +12 -0
- package/src/{read.js → cli/read.js} +0 -0
- package/src/fxp.d.ts +74 -0
- package/src/fxp.js +11 -0
- package/src/util.js +4 -22
- package/src/validator.js +53 -27
- package/src/xmlbuilder/json2xml.js +234 -0
- package/src/xmlbuilder/orderedJs2Xml.js +71 -0
- package/src/xmlbuilder/prettifyJs2Xml.js +0 -0
- package/src/xmlparser/OptionsBuilder.js +62 -0
- package/src/xmlparser/OrderedObjParser.js +407 -0
- package/src/xmlparser/XMLParser.js +36 -0
- package/src/xmlparser/node2json.js +101 -0
- package/src/xmlparser/xmlNode.js +23 -0
- package/src/json2xml.js +0 -268
- package/src/nimndata.js +0 -144
- package/src/node2json.js +0 -42
- package/src/node2json_str.js +0 -63
- package/src/parser.d.ts +0 -78
- package/src/parser.js +0 -76
- package/src/xmlNode.js +0 -17
- package/src/xmlstr2xmlnode.js +0 -337
package/README.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
# [fast-xml-parser](https://www.npmjs.com/package/fast-xml-parser)
|
|
4
2
|
[](#backers) [](#sponsors) [](https://snyk.io/test/github/naturalintelligence/fast-xml-parser)
|
|
5
3
|
[![NPM quality][quality-image]][quality-url]
|
|
@@ -12,312 +10,125 @@
|
|
|
12
10
|
[quality-url]: http://packagequality.com/#?package=fast-xml-parser
|
|
13
11
|
|
|
14
12
|
|
|
15
|
-
Validate XML, Parse XML to JS
|
|
16
|
-
|
|
17
|
-
To cover expenses, we're planning to launch [FXP Enterprise](https://github.com/NaturalIntelligence/fxp-ent) edition in parallel. Watch it for further updates, if you're interested.
|
|
18
|
-
|
|
19
|
-

|
|
13
|
+
Validate XML, Parse XML to JS Object, or Build XML from JS Object without C/C++ based libraries and no callback.
|
|
20
14
|
|
|
21
15
|
<a href="https://opencollective.com/fast-xml-parser/donate" target="_blank">
|
|
22
16
|
<img src="https://opencollective.com/fast-xml-parser/donate/button@2x.png?color=blue" width=200 />
|
|
23
17
|
</a>
|
|
24
18
|
<a href="https://paypal.me/naturalintelligence"> <img src="static/img/support_paypal.svg" alt="Stubmatic donate button" width="200"/></a>
|
|
25
19
|
|
|
20
|
+
Check [ThankYouBackers](https://github.com/NaturalIntelligence/ThankYouBackers) for our contributors
|
|
21
|
+
|
|
26
22
|
## Users
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<a href="https://
|
|
30
|
-
<a href="https://
|
|
31
|
-
<a href="
|
|
32
|
-
<a href="
|
|
33
|
-
<a href="
|
|
34
|
-
<a href="https://
|
|
35
|
-
<a href="
|
|
36
|
-
<a href="
|
|
37
|
-
<a href="http://
|
|
38
|
-
<a href="
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
<
|
|
43
|
-
<a href="https://www.tourstream.eu/" title="tourstream" > <img src="https://avatars1.githubusercontent.com/u/23242088" width="80px" ></a>
|
|
44
|
-
<a href="https://www.atomist.com/" title="Atomist" > <img src="https://avatars3.githubusercontent.com/u/19392" width="80px" ></a>
|
|
45
|
-
<a href="http://www.opuscapita.com/" title="OpusCapita" > <img src="https://avatars1.githubusercontent.com/u/23256480" width="80px" ></a>
|
|
46
|
-
<a href="https://nevatrip.ru/" title="nevatrip" > <img src="https://avatars2.githubusercontent.com/u/35730984" width="80px" ></a>
|
|
47
|
-
<a href="http://www.smartbear.com" title="SmartBear Software" > <img src="https://avatars2.githubusercontent.com/u/1644671" width="80px" ></a>
|
|
48
|
-
<a href="http://eosnavigator.com/" title="nevatrip" > <img src="https://avatars1.githubusercontent.com/u/40260563" width="80px" ></a>
|
|
49
|
-
<a href="http://nasa.github.io/" title="NASA" > <img src="https://avatars0.githubusercontent.com/u/848102" width="80px" ></a>
|
|
50
|
-
<a href="http://qgis.org/" title="QGIS" > <img src="https://avatars2.githubusercontent.com/u/483444" width="80px" ></a>
|
|
51
|
-
<a href="http://www.craft.ai/" title="craft ai" > <img src="https://avatars1.githubusercontent.com/u/12046764" width="80px" ></a>
|
|
52
|
-
<a href="http://brownspace.org/" title="Brown Space Engineering" > <img src="https://avatars2.githubusercontent.com/u/5504507" width="80px" ></a>
|
|
53
|
-
<a href="http://www.appcelerator.com/" title="Team Appcelerator" > <img src="https://avatars1.githubusercontent.com/u/82188" width="80px" ></a>
|
|
54
|
-
<a href="https://xmllint.com/" title="XML Lint" > <img src="https://xmllint.com/assets/logo.png" width="80px" ></a>
|
|
55
|
-
<a href="https://github.com/prettier" title="Prettier" > <img src="https://avatars0.githubusercontent.com/u/25822731" width="80px" ></a>
|
|
56
|
-
<a href="https://github.com/dolanmiu/docx" title="docx" > <img src="https://i.imgur.com/37uBGhO.gif" width="80px" ></a>
|
|
57
|
-
<a href="http://orange-opensource.github.io/" title="Open Source by Orange" > <img src="https://avatars3.githubusercontent.com/u/1506386" width="80px" ></a>
|
|
58
|
-
<a href="http://www.ybrain.com/" title="YBRAIN Inc." > <img src="https://avatars2.githubusercontent.com/u/38232440" width="80px" ></a>
|
|
59
|
-
<a href="http://99bitcoins.com/" title="99 bitcoins" > <img src="https://avatars0.githubusercontent.com/u/9527779" width="80px" ></a>
|
|
60
|
-
<a href="https://wechaty.github.io/wechaty/" title="Wechaty" > <img src="https://avatars0.githubusercontent.com/u/21285357" width="80px" ></a>
|
|
61
|
-
<a href="https://opendatakit.org" title="Open Data Kit" > <img src="https://avatars0.githubusercontent.com/u/6222985" width="80px" ></a>
|
|
62
|
-
<a href="https://ridibooks.com" title="RIDI Books" > <img src="https://avatars1.githubusercontent.com/u/24955411" width="80px" ></a>
|
|
63
|
-
<a href="http://signalk.org" title="Signal K" > <img src="https://avatars1.githubusercontent.com/u/7126740" width="80px" ></a>
|
|
64
|
-
<a href="http://brain.js.org/" title="brain.js" > <img src="https://avatars2.githubusercontent.com/u/23732838" width="80px" ></a>
|
|
65
|
-
<a href="https://skygear.io/" title="Skegear" > <img src="https://avatars1.githubusercontent.com/u/15025887" width="80px" ></a>
|
|
66
|
-
<a href="https://npmjs.com/" title="npm" > <img src="https://avatars0.githubusercontent.com/u/6078720" width="80px" ></a>
|
|
67
|
-
<a href=" https://www.mindpointgroup.com" title="mindpointgroup" > <img src="https://avatars1.githubusercontent.com/u/6413533" width="80px" ></a>
|
|
68
|
-
<a href="http://www.acuantcorp.com/" title="Acuant Inc" > <img src="https://avatars3.githubusercontent.com/u/11580319?s=200&v=4" width="80px" ></a>
|
|
69
|
-
<a href="https://www.wazuh.com/" title="wazuh" > <img src="https://avatars2.githubusercontent.com/u/13752566" width="80px" ></a>
|
|
70
|
-
<a href="https://orbs.com/" title="ORBS The Hybrid Blockchain" > <img src="https://avatars1.githubusercontent.com/u/33665977" width="80px" ></a>
|
|
71
|
-
<a href="https://texlab.netlify.com/" title="latex-lsp" > <img src="https://avatars1.githubusercontent.com/u/48360002" width="80px" ></a>
|
|
72
|
-
<a href="https://frontside.io/" title="The Frontside " > <img src="https://avatars1.githubusercontent.com/u/223096" width="80px" ></a>
|
|
73
|
-
<a href="https://creditsense.com.au/" title="Credit Sense Australia " > <img src="https://avatars0.githubusercontent.com/u/46947118" width="80px" ></a>
|
|
74
|
-
<a href="https://www.hustunique.com/" title="UniqueStudio" > <img src="https://avatars1.githubusercontent.com/u/4847684" width="80px" ></a>
|
|
75
|
-
<a href="http://www.openforis.org/" title="Open Foris" > <img src="https://avatars2.githubusercontent.com/u/1212750" width="80px" ></a>
|
|
76
|
-
<a href="#" title="NHS Connect" > <img src="https://avatars3.githubusercontent.com/u/20316669" width="80px" ></a>
|
|
77
|
-
<a href="https://tradle.io/" title="Tradle" > <img src="https://avatars2.githubusercontent.com/u/9482126" width="80px" ></a>
|
|
78
|
-
<a href="http://www.anl.gov/" title="Argonne National Laboratory" > <img src="https://avatars0.githubusercontent.com/u/10468712" width="80px" ></a>
|
|
79
|
-
<a href="https://simpleicons.org/" title="Simple Icons" > <img src="https://avatars2.githubusercontent.com/u/29872746" width="80px" ></a>
|
|
80
|
-
<a href="https://stoplight.io/" title="Stoplight" > <img src="https://avatars1.githubusercontent.com/u/10767217" width="80px" ></a>
|
|
81
|
-
<a href="http://www.fda.gov/" title="Food and Drug Administration " > <img src="https://avatars2.githubusercontent.com/u/6471964" width="80px" ></a>
|
|
82
|
-
<a href="http://www.magento.com/" title="Magento" > <img src="https://avatars2.githubusercontent.com/u/168457" width="80px" ></a>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
The list of users is collected either from the list published by Github, cummunicated directly through mails/chat , or from other resources. If you feel that your name in the above list is incorrectly published or you're not the user of this library anymore then you can inform us to remove it. We'll do the necessary changes ASAP.
|
|
23
|
+
|
|
24
|
+
<a href="https://github.com/renovatebot/renovate" title="renovate" ><img src="https://avatars1.githubusercontent.com/u/38656520" width="60px" ></a>
|
|
25
|
+
<a href="https://vmware.com/" title="vmware" > <img src="https://avatars0.githubusercontent.com/u/473334" width="60px" ></a>
|
|
26
|
+
<a href="https://opensource.microsoft.com/" title="microsoft" > <img src="https://avatars0.githubusercontent.com/u/6154722" width="60px" ></a>
|
|
27
|
+
<a href="http://ibm.github.io/" title="IBM" > <img src="https://avatars2.githubusercontent.com/u/1459110" width="60px" ></a>
|
|
28
|
+
<a href="http://www.smartbear.com" title="SmartBear Software" > <img src="https://avatars2.githubusercontent.com/u/1644671" width="60px" ></a>
|
|
29
|
+
<a href="http://nasa.github.io/" title="NASA" > <img src="https://avatars0.githubusercontent.com/u/848102" width="60px" ></a>
|
|
30
|
+
<a href="https://github.com/prettier" title="Prettier" > <img src="https://avatars0.githubusercontent.com/u/25822731" width="60px" ></a>
|
|
31
|
+
<a href="http://brain.js.org/" title="brain.js" > <img src="https://avatars2.githubusercontent.com/u/23732838" width="60px" ></a>
|
|
32
|
+
<a href="#" title="NHS Connect" > <img src="https://avatars3.githubusercontent.com/u/20316669" width="60px" ></a>
|
|
33
|
+
<a href="http://www.fda.gov/" title="Food and Drug Administration " > <img src="https://avatars2.githubusercontent.com/u/6471964" width="60px" ></a>
|
|
34
|
+
<a href="http://www.magento.com/" title="Magento" > <img src="https://avatars2.githubusercontent.com/u/168457" width="60px" ></a>
|
|
35
|
+
|
|
36
|
+
Check the list of all known users [here](./USERs.md);
|
|
37
|
+
|
|
38
|
+
<small>The list of users is collected either from the list published by Github, cummunicated directly through mails/chat , or from other resources. If you feel that your name in the above list is incorrectly published or you're not the user of this library anymore then you can inform us to remove it. We'll do the necessary changes ASAP.</small>
|
|
86
39
|
|
|
87
40
|
### Main Features
|
|
88
41
|
|
|
89
42
|
<img align="right" src="static/img/fxp_logo.png" width="180px" alt="FXP logo"/>
|
|
90
43
|
|
|
91
44
|
* Validate XML data syntactically
|
|
92
|
-
*
|
|
93
|
-
*
|
|
45
|
+
* Parse XML to JS Object
|
|
46
|
+
* Build XML from JS Object
|
|
94
47
|
* Works with node packages, in browser, and in CLI (press try me button above for demo)
|
|
95
48
|
* Faster than any pure JS implementation.
|
|
96
49
|
* It can handle big files (tested up to 100mb).
|
|
97
|
-
*
|
|
98
|
-
* You can parse CDATA as a separate property.
|
|
99
|
-
* You can prefix attributes or group them to a separate property. Or they can be ignored from the result completely.
|
|
100
|
-
* You can parse tag's or attribute's value to primitive type: string, integer, float, hexadecimal, or boolean. And can optionally decode for HTML char.
|
|
101
|
-
* You can remove namespace from tag or attribute name while parsing
|
|
102
|
-
* It supports boolean attributes, if configured.
|
|
50
|
+
* Controlled parsing using various options
|
|
103
51
|
|
|
104
52
|
## How to use
|
|
105
53
|
|
|
106
|
-
To use
|
|
107
|
-
|
|
108
|
-
|
|
54
|
+
To use as package dependency
|
|
55
|
+
`$ npm install fast-xml-parser`
|
|
56
|
+
or
|
|
57
|
+
`$ yarn add fast-xml-parser`
|
|
109
58
|
|
|
110
|
-
To use
|
|
111
|
-
|
|
112
|
-
`$npm install fast-xml-parser -g`
|
|
59
|
+
To use as system command
|
|
60
|
+
`$ npm install fast-xml-parser -g`
|
|
113
61
|
|
|
114
62
|
To use it on a **webpage** include it from a [CDN](https://cdnjs.com/libraries/fast-xml-parser)
|
|
115
63
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
```js
|
|
120
|
-
var jsonObj = parser.parse(xmlData [,options] );
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
```js
|
|
124
|
-
var parser = require('fast-xml-parser');
|
|
125
|
-
var he = require('he');
|
|
126
|
-
|
|
127
|
-
var options = {
|
|
128
|
-
attributeNamePrefix : "@_",
|
|
129
|
-
attrNodeName: "attr", //default is 'false'
|
|
130
|
-
textNodeName : "#text",
|
|
131
|
-
ignoreAttributes : true,
|
|
132
|
-
ignoreNameSpace : false,
|
|
133
|
-
allowBooleanAttributes : false,
|
|
134
|
-
parseNodeValue : true,
|
|
135
|
-
parseAttributeValue : false,
|
|
136
|
-
trimValues: true,
|
|
137
|
-
cdataTagName: "__cdata", //default is 'false'
|
|
138
|
-
cdataPositionChar: "\\c",
|
|
139
|
-
parseTrueNumberOnly: false,
|
|
140
|
-
numParseOptions:{
|
|
141
|
-
hex: true,
|
|
142
|
-
leadingZeros: true,
|
|
143
|
-
//skipLike: /\+[0-9]{10}/
|
|
144
|
-
}
|
|
145
|
-
arrayMode: false, //"strict"
|
|
146
|
-
attrValueProcessor: (val, attrName) => he.decode(val, {isAttributeValue: true}),//default is a=>a
|
|
147
|
-
tagValueProcessor : (val, tagName) => he.decode(val), //default is a=>a
|
|
148
|
-
stopNodes: ["parse-me-as-string"]
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
if( parser.validate(xmlData) === true) { //optional (it'll return an object in case it's not valid)
|
|
152
|
-
var jsonObj = parser.parse(xmlData,options);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Intermediate obj
|
|
156
|
-
var tObj = parser.getTraversalObj(xmlData,options);
|
|
157
|
-
var jsonObj = parser.convertToJson(tObj,options);
|
|
158
|
-
|
|
159
|
-
```
|
|
160
|
-
As you can notice in the above code, validator is not embedded with in the parser and expected to be called separately. However, you can pass `true` or validation options as 3rd parameter to the parser to trigger validator internally. It is same as above example.
|
|
161
|
-
|
|
162
|
-
```js
|
|
163
|
-
try{
|
|
164
|
-
var jsonObj = parser.parse(xmlData,options, true);
|
|
165
|
-
}catch(error){
|
|
166
|
-
console.log(error.message)
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
Validator returns the following object in case of error;
|
|
171
|
-
```js
|
|
172
|
-
{
|
|
173
|
-
err: {
|
|
174
|
-
code: code,
|
|
175
|
-
msg: message,
|
|
176
|
-
line: lineNumber,
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
#### Note: [he](https://www.npmjs.com/package/he) library is used in this example
|
|
183
|
-
|
|
184
|
-
<details>
|
|
185
|
-
<summary>OPTIONS :</summary>
|
|
186
|
-
|
|
187
|
-
* **attributeNamePrefix** : prepend given string to attribute name for identification
|
|
188
|
-
* **attrNodeName**: (Valid name) Group all the attributes as properties of given name.
|
|
189
|
-
* **ignoreAttributes** : Ignore attributes to be parsed.
|
|
190
|
-
* **ignoreNameSpace** : Remove namespace string from tag and attribute names.
|
|
191
|
-
* **allowBooleanAttributes** : a tag can have attributes without any value
|
|
192
|
-
* **parseNodeValue** : Parse the value of text node to float, integer, or boolean.
|
|
193
|
-
* **parseAttributeValue** : Parse the value of an attribute to float, integer, or boolean.
|
|
194
|
-
* **trimValues** : trim string values of an attribute or node
|
|
195
|
-
* **decodeHTMLchar** : This options has been removed from 3.3.4. Instead, use tagValueProcessor, and attrValueProcessor. See above example.
|
|
196
|
-
* **cdataTagName** : If specified, parser parse CDATA as nested tag instead of adding it's value to parent tag.
|
|
197
|
-
* **cdataPositionChar** : It'll help to covert JSON back to XML without losing CDATA position.
|
|
198
|
-
* **parseTrueNumberOnly**: if true then values like "+123", or "0123" will not be parsed as number.
|
|
199
|
-
* **arrayMode** : When `false`, a tag with single occurrence is parsed as an object but as an array in case of multiple occurences. When `true`, a tag will be parsed as an array always excluding leaf nodes. When `strict`, all the tags will be parsed as array only. When instance of `RegEx`, only tags will be parsed as array that match the regex. When `function` a tag name is passed to the callback that can be checked.
|
|
200
|
-
* **tagValueProcessor** : Process tag value during transformation. Like HTML decoding, word capitalization, etc. Applicable in case of string only.
|
|
201
|
-
* **attrValueProcessor** : Process attribute value during transformation. Like HTML decoding, word capitalization, etc. Applicable in case of string only.
|
|
202
|
-
* **stopNodes** : an array of tag names which are not required to be parsed. Instead their values are parsed as string.
|
|
203
|
-
|
|
204
|
-
</details>
|
|
205
|
-
|
|
206
|
-
<details>
|
|
207
|
-
<summary>To use from <b>command line</b></summary>
|
|
64
|
+
**Example**
|
|
208
65
|
|
|
66
|
+
As CLI command
|
|
209
67
|
```bash
|
|
210
|
-
$
|
|
211
|
-
$cat xmlfile.xml | xml2js [-ns|-a|-c|-v|-V] [-o outputfile.json]
|
|
68
|
+
$ fxparser some.xml
|
|
212
69
|
```
|
|
213
70
|
|
|
214
|
-
|
|
215
|
-
* -a : To ignore attributes
|
|
216
|
-
* -c : To ignore value conversion (i.e. "-3" will not be converted to number -3)
|
|
217
|
-
* -v : validate before parsing
|
|
218
|
-
* -V : only validate
|
|
219
|
-
</details>
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
<details>
|
|
223
|
-
<summary>To use it <b>on webpage</b></summary>
|
|
224
|
-
|
|
71
|
+
In a node js project
|
|
225
72
|
```js
|
|
226
|
-
|
|
227
|
-
if (result !== true) console.log(result.err);
|
|
228
|
-
var jsonObj = parser.parse(xmlData);
|
|
229
|
-
```
|
|
230
|
-
</details>
|
|
73
|
+
const { XMLParser, XMLBuilder, XMLValidator} = require("../src/fxp");
|
|
231
74
|
|
|
232
|
-
|
|
75
|
+
const parser = new XMLParser();
|
|
76
|
+
let jObj = parser.parse(XMLdata);
|
|
233
77
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
//default options need not to set
|
|
237
|
-
var defaultOptions = {
|
|
238
|
-
attributeNamePrefix : "@_",
|
|
239
|
-
attrNodeName: "@", //default is false
|
|
240
|
-
textNodeName : "#text",
|
|
241
|
-
ignoreAttributes : true,
|
|
242
|
-
cdataTagName: "__cdata", //default is false
|
|
243
|
-
cdataPositionChar: "\\c",
|
|
244
|
-
format: false,
|
|
245
|
-
indentBy: " ",
|
|
246
|
-
supressEmptyNode: false,
|
|
247
|
-
tagValueProcessor: a=> he.encode(a, { useNamedReferences: true}),// default is a=>a
|
|
248
|
-
attrValueProcessor: a=> he.encode(a, {isAttributeValue: isAttribute, useNamedReferences: true})// default is a=>a
|
|
249
|
-
};
|
|
250
|
-
var parser = new Parser(defaultOptions);
|
|
251
|
-
var xml = parser.parse(json_or_js_obj);
|
|
78
|
+
const builder = new XMLBuilder();
|
|
79
|
+
const xmlContent = builder.build(jObj);
|
|
252
80
|
```
|
|
253
81
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
* **cdataTagName** : If specified, parse matching tag as CDATA
|
|
264
|
-
* **cdataPositionChar** : Identify the position where CDATA tag should be placed. If it is blank then CDATA will be added in the last of tag's value.
|
|
265
|
-
* **format** : If set to true, then format the XML output.
|
|
266
|
-
* **indentBy** : indent by this char `when` format is set to `true`
|
|
267
|
-
* **supressEmptyNode** : If set to `true`, tags with no value (text or nested tags) are written as self closing tags.
|
|
268
|
-
* **tagValueProcessor** : Process tag value during transformation. Like HTML encoding, word capitalization, etc. Applicable in case of string only.
|
|
269
|
-
* **attrValueProcessor** : Process attribute value during transformation. Like HTML encoding, word capitalization, etc. Applicable in case of string only.
|
|
270
|
-
</details>
|
|
271
|
-
|
|
272
|
-
## Benchmark
|
|
273
|
-
|
|
274
|
-
#### XML to JSON
|
|
275
|
-
|
|
276
|
-

|
|
277
|
-
|
|
278
|
-
<details>
|
|
279
|
-
<summary>report</summary>
|
|
82
|
+
In a HTML page
|
|
83
|
+
```html
|
|
84
|
+
<script src="path/to/fxparser.js"></script>
|
|
85
|
+
:
|
|
86
|
+
<script>
|
|
87
|
+
const parser = new fxparser.XMLParser();
|
|
88
|
+
parser.parse(xmlContent);
|
|
89
|
+
</script>
|
|
90
|
+
```
|
|
280
91
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
| 1.5m | 14918.47793 | 13.23366098 | 5.90682005 |
|
|
285
|
-
| 13m | 1.834479235 | 1.135582008 | -1 |
|
|
286
|
-
| 1.3k with CDATA | 30583.35319 | 43160.52342 | 8398.556349 |
|
|
287
|
-
| 1.3m with CDATA | 27.29266471 | 52.68877009 | 7.966000795 |
|
|
288
|
-
| 1.6k with cdata,prolog,doctype | 27690.26082 | 41433.98547 | 7872.399268 |
|
|
289
|
-
| 98m | 0.08473858148 | 0.2600104004 | -1 |
|
|
92
|
+
### Documents
|
|
93
|
+
**v3**
|
|
94
|
+
* [documents](./docs/v3/docs.md)
|
|
290
95
|
|
|
291
|
-
|
|
292
|
-
|
|
96
|
+
**v4**
|
|
97
|
+
1. [GettingStarted.md](./docs/v4/1.GettingStarted.md)
|
|
98
|
+
2. [XML Parser](./docs/v4/2.XMLparseOptions.md)
|
|
99
|
+
3. [XML Builder](./docs/v4/3.XMLBuilder.md)
|
|
100
|
+
4. [XML Validator](./docs/v4/4.XMLValidator.md)
|
|
293
101
|
|
|
102
|
+
## Performance
|
|
294
103
|
|
|
295
|
-
|
|
104
|
+
### XML Parser
|
|
296
105
|
|
|
297
|
-

|
|
298
107
|
|
|
299
|
-
|
|
300
|
-
|
|
108
|
+
**Large files**
|
|
109
|
+

|
|
301
110
|
|
|
302
|
-
|
|
303
|
-
|------------|-----------------|-----------------|
|
|
304
|
-
| 1.3k | 160148.9801 | 10384.99401|
|
|
305
|
-
| 1.1m | 173.6374831 | 8.611884025|
|
|
111
|
+
### XML Builder
|
|
306
112
|
|
|
307
|
-
|
|
113
|
+

|
|
308
114
|
|
|
309
|
-
|
|
115
|
+
<small>negative means error</small>
|
|
310
116
|
|
|
311
|
-
|
|
312
|
-
- **[imglab](https://github.com/NaturalIntelligence/imglab)** : Speedup and simplify image labeling / annotation. Supports multiple formats, one click annotation, easy interface and much more. There are more than half million images are being annotated every month using this tool.
|
|
313
|
-
- [stubmatic](https://github.com/NaturalIntelligence/Stubmatic) : Create fake webservices, DynamoDB or S3 servers, Manage fake/mock stub data, Or fake any HTTP(s) call.
|
|
314
|
-
- **[अनुमार्गक (anumargak)](https://github.com/NaturalIntelligence/anumargak)** : The fastest and simple router for node js web frameworks with many unique features.
|
|
315
|
-
- [मुनीम (Muneem)](https://github.com/muneem4node/muneem) : A webframework made for all team members. Fast and Featured.
|
|
316
|
-
- [शब्दावली (shabdawali)](https://github.com/amitguptagwl/shabdawali) : Amazing human like typing effects beyond your imagination.
|
|
117
|
+
## Our other projects and research you must try
|
|
317
118
|
|
|
119
|
+
* **[BigBit standard](https://github.com/amitguptagwl/bigbit)** :
|
|
120
|
+
* Single text encoding to replace UTF-8, UTF-16, UTF-32 and more with less memory.
|
|
121
|
+
* Single Numeric datatype alternative of integer, float, double, long, decimal and more without precision loss.
|
|
122
|
+
* **[Cytorus](https://github.com/NaturalIntelligence/cytorus)**: Now be specific and flexible while running E2E tests.
|
|
123
|
+
* Run tests only for a particular User Story
|
|
124
|
+
* Run tests for a route or from a route
|
|
125
|
+
* Customizable reporting
|
|
126
|
+
* Central dashboard for better monitoring
|
|
127
|
+
* **[Stubmatic](https://github.com/NaturalIntelligence/Stubmatic)** : Create fake webservices, DynamoDB or S3 servers, Manage fake/mock stub data, Or fake any HTTP(s) call.
|
|
318
128
|
|
|
319
129
|
|
|
320
|
-
##
|
|
130
|
+
## Supporters
|
|
131
|
+
### Contributors
|
|
321
132
|
|
|
322
133
|
This project exists thanks to [all](graphs/contributors) the people who contribute. [[Contribute](docs/CONTRIBUTING.md)].
|
|
323
134
|
<!-- <a href="graphs/contributors"><img src="https://opencollective.com/fast-xml-parser/contributors.svg?width=890&button=false" /></a> -->
|
|
@@ -329,16 +140,16 @@ This project exists thanks to [all](graphs/contributors) the people who contribu
|
|
|
329
140
|
### All Contributors -->
|
|
330
141
|
<a href="graphs/contributors"><img src="https://opencollective.com/fast-xml-parser/contributors.svg?width=890&button=false" /></a>
|
|
331
142
|
|
|
332
|
-
|
|
143
|
+
### Backers
|
|
333
144
|
|
|
334
145
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/fast-xml-parser#backer)]
|
|
335
146
|
|
|
336
147
|
<a href="https://opencollective.com/fast-xml-parser#backers" target="_blank"><img src="https://opencollective.com/fast-xml-parser/backers.svg?width=890"></a>
|
|
337
148
|
|
|
338
149
|
|
|
339
|
-
|
|
150
|
+
### Sponsors
|
|
340
151
|
|
|
341
|
-
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
|
|
152
|
+
<small>[[Become a sponsor](https://opencollective.com/fast-xml-parser#sponsor)] Support this project by becoming a sponsor. Your logo will show up here with a link to your website. Please also share your detail so we can thankyou on SocialMedia.</small>
|
|
342
153
|
|
|
343
154
|
<a href="https://opencollective.com/fast-xml-parser/sponsor/0/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/0/avatar.svg"></a>
|
|
344
155
|
<a href="https://opencollective.com/fast-xml-parser/sponsor/1/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/1/avatar.svg"></a>
|
|
@@ -352,5 +163,6 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
352
163
|
<a href="https://opencollective.com/fast-xml-parser/sponsor/9/website" target="_blank"><img src="https://opencollective.com/fast-xml-parser/sponsor/9/avatar.svg"></a>
|
|
353
164
|
|
|
354
165
|
# License
|
|
355
|
-
|
|
356
166
|
* MIT License
|
|
167
|
+
|
|
168
|
+

|
package/package.json
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-xml-parser",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Validate XML
|
|
5
|
-
"main": "./src/
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
4
|
+
"description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
|
|
5
|
+
"main": "./src/fxp.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "jasmine spec/*spec.js",
|
|
7
|
+
"test": "nyc --reporter=lcov --reporter=text jasmine spec/*spec.js",
|
|
8
8
|
"unit": "jasmine",
|
|
9
|
+
"coverage": "nyc report --reporter html --reporter text -t .nyc_output --report-dir .nyc_output/summary",
|
|
9
10
|
"perf": "node ./benchmark/perfTest3.js",
|
|
10
11
|
"lint": "eslint src/*.js spec/*.js",
|
|
11
12
|
"bundle": "webpack && webpack --config webpack-prod.config.js",
|
|
12
|
-
"coverage": "istanbul cover -x \"cli.js\" -x \"spec/*spec.js\" jasmine spec/*spec.js;",
|
|
13
|
-
"coverage:check": "istanbul check-coverage --branch 90 --statement 90",
|
|
14
13
|
"prettier": "prettier --write src/**/*.js",
|
|
15
14
|
"publish-please": "publish-please",
|
|
16
|
-
"
|
|
15
|
+
"checkReadiness": "publish-please --dry-run"
|
|
17
16
|
},
|
|
18
17
|
"bin": {
|
|
19
|
-
"
|
|
18
|
+
"fxparser": "./src/cli/cli.js"
|
|
20
19
|
},
|
|
21
20
|
"repository": {
|
|
22
21
|
"type": "git",
|
|
@@ -31,42 +30,16 @@
|
|
|
31
30
|
"x2js",
|
|
32
31
|
"xml2json",
|
|
33
32
|
"js",
|
|
34
|
-
"traversable",
|
|
35
33
|
"cli",
|
|
36
|
-
"command",
|
|
37
34
|
"validator",
|
|
38
35
|
"validate",
|
|
39
36
|
"transformer",
|
|
40
|
-
"checker",
|
|
41
37
|
"assert",
|
|
42
|
-
"big",
|
|
43
38
|
"js2xml",
|
|
44
39
|
"json2xml",
|
|
45
|
-
"nimn",
|
|
46
|
-
"xml2nimn",
|
|
47
|
-
"locale",
|
|
48
40
|
"html"
|
|
49
41
|
],
|
|
50
42
|
"author": "Amit Gupta (https://amitkumargupta.work/)",
|
|
51
|
-
"contributors": [
|
|
52
|
-
{
|
|
53
|
-
"name": "Alfonso Muñoz-Pomer Fuentes",
|
|
54
|
-
"email": "amunoz@ebi.ac.uk",
|
|
55
|
-
"url": "https://github.com/alfonsomunozpomer"
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
"name": "Steve Reichenbach",
|
|
59
|
-
"url": "https://github.com/EyesOnlyNet"
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
"name": "Vohmyanin Sergey Vasilevich",
|
|
63
|
-
"url": "http://delagen.livejournal.com"
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
"name": "Andrew Udvare",
|
|
67
|
-
"url": "https://github.com/Tatsh"
|
|
68
|
-
}
|
|
69
|
-
],
|
|
70
43
|
"license": "MIT",
|
|
71
44
|
"devDependencies": {
|
|
72
45
|
"@babel/core": "^7.13.10",
|
|
@@ -76,16 +49,14 @@
|
|
|
76
49
|
"babel-loader": "^8.2.2",
|
|
77
50
|
"eslint": "^5.16.0",
|
|
78
51
|
"he": "^1.2.0",
|
|
79
|
-
"http-server": "^0.12.3",
|
|
80
|
-
"istanbul": "^0.4.5",
|
|
81
52
|
"jasmine": "^3.6.4",
|
|
82
|
-
"
|
|
53
|
+
"nyc": "^15.1.0",
|
|
83
54
|
"prettier": "^1.19.1",
|
|
84
55
|
"publish-please": "^5.5.2",
|
|
85
56
|
"webpack": "^4.46.0",
|
|
86
57
|
"webpack-cli": "^3.3.12"
|
|
87
58
|
},
|
|
88
|
-
"typings": "src/
|
|
59
|
+
"typings": "src/fxp.d.ts",
|
|
89
60
|
"funding": {
|
|
90
61
|
"type": "paypal",
|
|
91
62
|
"url": "https://paypal.me/naturalintelligence"
|
|
@@ -3,26 +3,19 @@
|
|
|
3
3
|
/*eslint-disable no-console*/
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
|
-
const
|
|
7
|
-
const readToEnd = require('./
|
|
6
|
+
const {XMLParser, XMLValidator} = require("../fxp");
|
|
7
|
+
const readToEnd = require('./read').readToEnd;
|
|
8
8
|
|
|
9
|
+
const version = require('./../../package.json').version;
|
|
9
10
|
if (process.argv[2] === '--help' || process.argv[2] === '-h') {
|
|
10
|
-
console.log(
|
|
11
|
-
console.log('----------------');
|
|
12
|
-
console.log('xml2js [-ns|-a|-c|-v|-V] <filename> [-o outputfile.json]');
|
|
13
|
-
console.log('cat xmlfile.xml | xml2js [-ns|-a|-c|-v|-V] [-o outputfile.json]');
|
|
14
|
-
console.log('-ns: remove namespace from tag and atrribute name.');
|
|
15
|
-
console.log("-a: don't parse attributes.");
|
|
16
|
-
console.log('-c: parse values to premitive type.');
|
|
17
|
-
console.log('-v: validate before parsing.');
|
|
18
|
-
console.log('-V: validate only.');
|
|
11
|
+
console.log(require("./man"));
|
|
19
12
|
} else if (process.argv[2] === '--version') {
|
|
20
|
-
console.log(
|
|
13
|
+
console.log(version);
|
|
21
14
|
} else {
|
|
22
15
|
const options = {
|
|
23
|
-
|
|
16
|
+
removeNSPrefix: true,
|
|
24
17
|
ignoreAttributes: false,
|
|
25
|
-
|
|
18
|
+
parseTagValue: true,
|
|
26
19
|
parseAttributeValue: true,
|
|
27
20
|
};
|
|
28
21
|
let fileName = '';
|
|
@@ -31,11 +24,11 @@ if (process.argv[2] === '--help' || process.argv[2] === '-h') {
|
|
|
31
24
|
let validateOnly = false;
|
|
32
25
|
for (let i = 2; i < process.argv.length; i++) {
|
|
33
26
|
if (process.argv[i] === '-ns') {
|
|
34
|
-
options.
|
|
27
|
+
options.removeNSPrefix = false;
|
|
35
28
|
} else if (process.argv[i] === '-a') {
|
|
36
29
|
options.ignoreAttributes = true;
|
|
37
30
|
} else if (process.argv[i] === '-c') {
|
|
38
|
-
options.
|
|
31
|
+
options.parseTagValue = false;
|
|
39
32
|
options.parseAttributeValue = false;
|
|
40
33
|
} else if (process.argv[i] === '-o') {
|
|
41
34
|
outputFileName = process.argv[++i];
|
|
@@ -48,20 +41,18 @@ if (process.argv[2] === '--help' || process.argv[2] === '-h') {
|
|
|
48
41
|
fileName = process.argv[i];
|
|
49
42
|
}
|
|
50
43
|
}
|
|
44
|
+
|
|
51
45
|
const callback = function(xmlData) {
|
|
52
46
|
let output = '';
|
|
53
47
|
if (validate) {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
output = JSON.stringify(parser.parse(xmlData, options), null, 4);
|
|
57
|
-
} else {
|
|
58
|
-
output = result;
|
|
59
|
-
}
|
|
48
|
+
const parser = new XMLParser(options);
|
|
49
|
+
output = parser.parse(xmlData,validate);
|
|
60
50
|
} else if (validateOnly) {
|
|
61
|
-
output =
|
|
51
|
+
output = XMLValidator.validate(xmlData);
|
|
62
52
|
process.exitCode = output === true ? 0 : 1;
|
|
63
53
|
} else {
|
|
64
|
-
|
|
54
|
+
const parser = new XMLParser(options);
|
|
55
|
+
output = JSON.stringify(parser.parse(xmlData,validate), null, 4);
|
|
65
56
|
}
|
|
66
57
|
if (outputFileName) {
|
|
67
58
|
writeToFile(outputFileName, output);
|
|
@@ -71,6 +62,7 @@ if (process.argv[2] === '--help' || process.argv[2] === '-h') {
|
|
|
71
62
|
};
|
|
72
63
|
|
|
73
64
|
try {
|
|
65
|
+
|
|
74
66
|
if (!fileName) {
|
|
75
67
|
readToEnd(process.stdin, function(err, data) {
|
|
76
68
|
if (err) {
|
package/src/cli/man.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = `Fast XML Parser 4.0.0
|
|
2
|
+
----------------
|
|
3
|
+
$ fxparser [-ns|-a|-c|-v|-V] <filename> [-o outputfile.json]
|
|
4
|
+
$ cat xmlfile.xml | fxparser [-ns|-a|-c|-v|-V] [-o outputfile.json]
|
|
5
|
+
|
|
6
|
+
Options
|
|
7
|
+
----------------
|
|
8
|
+
-ns: remove namespace from tag and atrribute name.
|
|
9
|
+
-a: don't parse attributes.
|
|
10
|
+
-c: parse values to premitive type.
|
|
11
|
+
-v: validate before parsing.
|
|
12
|
+
-V: validate only.`
|
|
File without changes
|