fast-xml-parser 3.17.2 → 3.17.6
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/LICENSE +10 -2
- package/README.md +23 -22
- package/package.json +16 -13
- package/src/node2json.js +3 -2
- package/src/parser.js +2 -2
- package/src/xmlstr2xmlnode.js +43 -25
- package/tasks/postinstall.js +0 -5
- package/yarn.lock +0 -4953
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
MIT License
|
|
1
|
+
Modified MIT License
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2017 Amit Kumar Gupta
|
|
4
4
|
|
|
@@ -9,7 +9,15 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
|
10
10
|
furnished to do so, subject to the following conditions:
|
|
11
11
|
|
|
12
|
-
If you use this library
|
|
12
|
+
If you use this library then you give us the rights to mention your
|
|
13
|
+
company/project name and logo in user's list without further permission required.
|
|
14
|
+
However, you can request to remove it when you're not the user of this library anymore.
|
|
15
|
+
We'll do the necessary changes within 30 days from the notice.
|
|
16
|
+
|
|
17
|
+
You're not allowed to publish the code of this library without giving credits to
|
|
18
|
+
the original author/maintainers or without permission. You're required to take
|
|
19
|
+
the permission from original author to remove any non-code changes which are purposefully
|
|
20
|
+
added to this project including pre/post install message, notification on README, etc.
|
|
13
21
|
|
|
14
22
|
The above copyright notice and this permission notice shall be included in all
|
|
15
23
|
copies or substantial portions of the Software.
|
package/README.md
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
# [fast-xml-parser](https://www.npmjs.com/package/fast-xml-parser)
|
|
4
|
+
[](#backers) [](#sponsors) [](https://snyk.io/test/github/naturalintelligence/fast-xml-parser)
|
|
5
|
+
[![NPM quality][quality-image]][quality-url]
|
|
6
|
+
[](https://travis-ci.org/NaturalIntelligence/fast-xml-parser)
|
|
7
|
+
[](https://coveralls.io/github/NaturalIntelligence/fast-xml-parser?branch=master)
|
|
8
|
+
[<img src="https://img.shields.io/badge/Try-me-blue.svg?colorA=FFA500&colorB=0000FF" alt="Try me"/>](https://naturalintelligence.github.io/fast-xml-parser/)
|
|
9
|
+
[](https://npm.im/fast-xml-parser)
|
|
10
|
+
|
|
11
|
+
[quality-image]: http://npm.packagequality.com/shield/fast-xml-parser.svg?style=flat-square
|
|
12
|
+
[quality-url]: http://packagequality.com/#?package=fast-xml-parser
|
|
13
|
+
|
|
14
|
+
|
|
2
15
|
Validate XML, Parse XML to JS/JSON and vice versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
|
|
3
16
|
|
|
4
|
-
|
|
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
|
+

|
|
5
20
|
|
|
21
|
+
<a href="https://opencollective.com/fast-xml-parser/donate" target="_blank">
|
|
22
|
+
<img src="https://opencollective.com/fast-xml-parser/donate/button@2x.png?color=blue" width=200 />
|
|
23
|
+
</a>
|
|
24
|
+
<a href="https://www.patreon.com/bePatron?u=9531404" data-patreon-widget-type="become-patron-button"><img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Become a Patron!" width="200" /></a>
|
|
25
|
+
<a href="https://paypal.me/naturalintelligence"> <img src="static/img/support_paypal.svg" alt="Stubmatic donate button" width="200"/></a>
|
|
6
26
|
|
|
7
27
|
## Users
|
|
8
28
|
List of some applications/projects using Fast XML Parser. (Raise an issue to submit yours)
|
|
@@ -64,25 +84,8 @@ List of some applications/projects using Fast XML Parser. (Raise an issue to sub
|
|
|
64
84
|
|
|
65
85
|
|
|
66
86
|
|
|
67
|
-
### Join this project as collaborator / maintainer.
|
|
68
87
|
|
|
69
88
|
|
|
70
|
-
[](#backers) [](#sponsors) [](https://snyk.io/test/github/naturalintelligence/fast-xml-parser)
|
|
71
|
-
[![NPM quality][quality-image]][quality-url]
|
|
72
|
-
[](https://travis-ci.org/NaturalIntelligence/fast-xml-parser)
|
|
73
|
-
[](https://coveralls.io/github/NaturalIntelligence/fast-xml-parser?branch=master)
|
|
74
|
-
[<img src="https://img.shields.io/badge/Try-me-blue.svg?colorA=FFA500&colorB=0000FF" alt="Try me"/>](https://naturalintelligence.github.io/fast-xml-parser/)
|
|
75
|
-
[](https://npm.im/fast-xml-parser)
|
|
76
|
-
|
|
77
|
-
[quality-image]: http://npm.packagequality.com/shield/fast-xml-parser.svg?style=flat-square
|
|
78
|
-
[quality-url]: http://packagequality.com/#?package=fast-xml-parser
|
|
79
|
-
|
|
80
|
-
<a href="https://opencollective.com/fast-xml-parser/donate" target="_blank">
|
|
81
|
-
<img src="https://opencollective.com/fast-xml-parser/donate/button@2x.png?color=blue" width=200 />
|
|
82
|
-
</a>
|
|
83
|
-
<a href="https://www.patreon.com/bePatron?u=9531404" data-patreon-widget-type="become-patron-button"><img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Become a Patron!" width="200" /></a>
|
|
84
|
-
<a href="https://www.paypal.me/amitkumarguptagwl"> <img src="static/img/support_paypal.svg" alt="Stubmatic donate button" width="200"/></a>
|
|
85
|
-
|
|
86
89
|
### Main Features
|
|
87
90
|
|
|
88
91
|
<img align="right" src="static/img/fxp_logo.png" width="180px" alt="FXP logo"/>
|
|
@@ -300,9 +303,6 @@ With the correct options, you can get the almost original XML without losing any
|
|
|
300
303
|
|
|
301
304
|
</details>
|
|
302
305
|
|
|
303
|
-
### Limitations
|
|
304
|
-
Currently FXP fails to parse XML with attributes has ">" in the value. This problem is left open as change in regex for its fix is degrading the performance. And the parser become very slow in case of long attribute names. However, it is not ignored and we're working on the fix.
|
|
305
|
-
|
|
306
306
|
### Worth to mention
|
|
307
307
|
|
|
308
308
|
- **[BigBit standard)](https://github.com/amitguptagwl/bigbit)** : A standard to represent any number in the universe in comparatively less space and without precision loss. A standard to save memory to represent any text string in comparision of UTF encodings.
|
|
@@ -313,9 +313,10 @@ With the correct options, you can get the almost original XML without losing any
|
|
|
313
313
|
- [शब्दावली (shabdawali)](https://github.com/amitguptagwl/shabdawali) : Amazing human like typing effects beyond your imagination.
|
|
314
314
|
|
|
315
315
|
|
|
316
|
+
|
|
316
317
|
## Contributors
|
|
317
318
|
|
|
318
|
-
This project exists thanks to [all](graphs/contributors) the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
|
319
|
+
This project exists thanks to [all](graphs/contributors) the people who contribute. [[Contribute](docs/CONTRIBUTING.md)].
|
|
319
320
|
<!-- <a href="graphs/contributors"><img src="https://opencollective.com/fast-xml-parser/contributors.svg?width=890&button=false" /></a> -->
|
|
320
321
|
<!--
|
|
321
322
|
### Lead Maintainers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-xml-parser",
|
|
3
|
-
"version": "3.17.
|
|
3
|
+
"version": "3.17.6",
|
|
4
4
|
"description": "Validate XML or Parse XML to JS/JSON very fast without C/C++ based libraries",
|
|
5
5
|
"main": "./src/parser.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"bundle": "webpack && webpack --config webpack-prod.config.js",
|
|
12
12
|
"coverage": "istanbul cover -x \"cli.js\" -x \"spec/*spec.js\" jasmine spec/*spec.js;",
|
|
13
13
|
"coverage:check": "istanbul check-coverage --branch 90 --statement 90",
|
|
14
|
-
"postinstall": "node tasks/postinstall.js || exit 0",
|
|
15
14
|
"prettier": "prettier --write src/**/*.js",
|
|
16
15
|
"publish-please": "publish-please",
|
|
17
16
|
"prepublishOnly": "publish-please guard"
|
|
@@ -68,23 +67,27 @@
|
|
|
68
67
|
"url": "https://github.com/Tatsh"
|
|
69
68
|
}
|
|
70
69
|
],
|
|
71
|
-
"license": "MIT",
|
|
70
|
+
"license": "MIT Modified",
|
|
72
71
|
"devDependencies": {
|
|
73
|
-
"@babel/core": "^7.
|
|
74
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
75
|
-
"@babel/preset-env": "^7.
|
|
76
|
-
"@babel/register": "^7.
|
|
77
|
-
"babel-loader": "^8.
|
|
72
|
+
"@babel/core": "^7.12.10",
|
|
73
|
+
"@babel/plugin-transform-runtime": "^7.12.10",
|
|
74
|
+
"@babel/preset-env": "^7.12.11",
|
|
75
|
+
"@babel/register": "^7.12.10",
|
|
76
|
+
"babel-loader": "^8.2.2",
|
|
78
77
|
"eslint": "^5.16.0",
|
|
79
78
|
"he": "^1.2.0",
|
|
80
79
|
"http-server": "^0.12.3",
|
|
81
80
|
"istanbul": "^0.4.5",
|
|
82
|
-
"jasmine": "^3.
|
|
81
|
+
"jasmine": "^3.6.3",
|
|
83
82
|
"nimnjs": "^1.3.2",
|
|
84
83
|
"prettier": "^1.19.1",
|
|
85
|
-
"publish-please": "^5.5.
|
|
86
|
-
"webpack": "^4.
|
|
87
|
-
"webpack-cli": "^3.3.
|
|
84
|
+
"publish-please": "^5.5.2",
|
|
85
|
+
"webpack": "^4.44.2",
|
|
86
|
+
"webpack-cli": "^3.3.12"
|
|
88
87
|
},
|
|
89
|
-
"typings": "src/parser.d.ts"
|
|
88
|
+
"typings": "src/parser.d.ts",
|
|
89
|
+
"funding": {
|
|
90
|
+
"type": "paypal",
|
|
91
|
+
"url": "https://paypal.me/naturalintelligence"
|
|
92
|
+
}
|
|
90
93
|
}
|
package/src/node2json.js
CHANGED
|
@@ -29,8 +29,9 @@ const convertToJson = function(node, options) {
|
|
|
29
29
|
if (node.child[tagname] && node.child[tagname].length > 1) {
|
|
30
30
|
jObj[tagname] = [];
|
|
31
31
|
for (var tag in node.child[tagname]) {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (node.child[tagname].hasOwnProperty(tag)){
|
|
33
|
+
jObj[tagname].push(convertToJson(node.child[tagname][tag], options));}
|
|
34
|
+
}
|
|
34
35
|
} else {
|
|
35
36
|
if(options.arrayMode === true){
|
|
36
37
|
const result = convertToJson(node.child[tagname][0], options)
|
package/src/parser.js
CHANGED
|
@@ -44,12 +44,12 @@ function print(xmlNode, indentation){
|
|
|
44
44
|
if(xmlNode.child){
|
|
45
45
|
console.log(indentation + "\"child\": {")
|
|
46
46
|
const indentation2 = indentation + indentation;
|
|
47
|
-
Object.keys(xmlNode.child).forEach( key
|
|
47
|
+
Object.keys(xmlNode.child).forEach( function(key) {
|
|
48
48
|
const node = xmlNode.child[key];
|
|
49
49
|
|
|
50
50
|
if(Array.isArray(node)){
|
|
51
51
|
console.log(indentation + "\""+key+"\" :[")
|
|
52
|
-
node.forEach( (item,index)
|
|
52
|
+
node.forEach( function(item,index) {
|
|
53
53
|
//console.log(indentation + " \""+index+"\" : [")
|
|
54
54
|
print(item, indentation2);
|
|
55
55
|
})
|
package/src/xmlstr2xmlnode.js
CHANGED
|
@@ -66,9 +66,9 @@ exports.props = props;
|
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Trim -> valueProcessor -> parse value
|
|
69
|
-
* @param {string} tagName
|
|
70
|
-
* @param {string} val
|
|
71
|
-
* @param {object} options
|
|
69
|
+
* @param {string} tagName
|
|
70
|
+
* @param {string} val
|
|
71
|
+
* @param {object} options
|
|
72
72
|
*/
|
|
73
73
|
function processTagValue(tagName, val, options) {
|
|
74
74
|
if (val) {
|
|
@@ -168,18 +168,20 @@ function buildAttributesMap(attrStr, options) {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
const getTraversalObj = function(xmlData, options) {
|
|
171
|
+
xmlData = xmlData.replace(/\r\n?/g, "\n");
|
|
171
172
|
options = buildOptions(options, defaultOptions, props);
|
|
172
173
|
const xmlObj = new xmlNode('!xml');
|
|
173
174
|
let currentNode = xmlObj;
|
|
174
175
|
let textData = "";
|
|
176
|
+
|
|
175
177
|
//function match(xmlData){
|
|
176
178
|
for(let i=0; i< xmlData.length; i++){
|
|
177
179
|
const ch = xmlData[i];
|
|
178
180
|
if(ch === '<'){
|
|
179
181
|
if( xmlData[i+1] === '/') {//Closing Tag
|
|
180
|
-
const closeIndex = xmlData
|
|
182
|
+
const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.")
|
|
181
183
|
let tagName = xmlData.substring(i+2,closeIndex).trim();
|
|
182
|
-
|
|
184
|
+
|
|
183
185
|
if(options.ignoreNameSpace){
|
|
184
186
|
const colonIndex = tagName.indexOf(":");
|
|
185
187
|
if(colonIndex !== -1){
|
|
@@ -207,19 +209,19 @@ const getTraversalObj = function(xmlData, options) {
|
|
|
207
209
|
textData = "";
|
|
208
210
|
i = closeIndex;
|
|
209
211
|
} else if( xmlData[i+1] === '?') {
|
|
210
|
-
i = xmlData
|
|
211
|
-
} else if(
|
|
212
|
-
i = xmlData
|
|
213
|
-
} else if( xmlData
|
|
214
|
-
const closeIndex = xmlData
|
|
215
|
-
const tagExp = xmlData.
|
|
216
|
-
if(tagExp.indexOf("[")
|
|
212
|
+
i = findClosingIndex(xmlData, "?>", i, "Pi Tag is not closed.")
|
|
213
|
+
} else if(xmlData.substr(i + 1, 3) === '!--') {
|
|
214
|
+
i = findClosingIndex(xmlData, "-->", i, "Comment is not closed.")
|
|
215
|
+
} else if( xmlData.substr(i + 1, 2) === '!D') {
|
|
216
|
+
const closeIndex = findClosingIndex(xmlData, ">", i, "DOCTYPE is not closed.")
|
|
217
|
+
const tagExp = xmlData.substring(i, closeIndex);
|
|
218
|
+
if(tagExp.indexOf("[") >= 0){
|
|
217
219
|
i = xmlData.indexOf("]>", i) + 1;
|
|
218
220
|
}else{
|
|
219
221
|
i = closeIndex;
|
|
220
222
|
}
|
|
221
|
-
}else if(
|
|
222
|
-
const closeIndex = xmlData
|
|
223
|
+
}else if(xmlData.substr(i + 1, 2) === '![') {
|
|
224
|
+
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2
|
|
223
225
|
const tagExp = xmlData.substring(i + 9,closeIndex);
|
|
224
226
|
|
|
225
227
|
//considerations
|
|
@@ -243,16 +245,16 @@ const getTraversalObj = function(xmlData, options) {
|
|
|
243
245
|
} else {
|
|
244
246
|
currentNode.val = (currentNode.val || '') + (tagExp || '');
|
|
245
247
|
}
|
|
246
|
-
|
|
248
|
+
|
|
247
249
|
i = closeIndex + 2;
|
|
248
250
|
}else {//Opening tag
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
251
|
+
const result = closingIndexForOpeningTag(xmlData, i+1)
|
|
252
|
+
let tagExp = result.data;
|
|
253
|
+
const closeIndex = result.index;
|
|
252
254
|
const separatorIndex = tagExp.indexOf(" ");
|
|
253
255
|
let tagName = tagExp;
|
|
254
256
|
if(separatorIndex !== -1){
|
|
255
|
-
tagName = tagExp.substr(0, separatorIndex).
|
|
257
|
+
tagName = tagExp.substr(0, separatorIndex).replace(/\s\s*$/, '');
|
|
256
258
|
tagExp = tagExp.substr(separatorIndex + 1);
|
|
257
259
|
}
|
|
258
260
|
|
|
@@ -262,7 +264,7 @@ const getTraversalObj = function(xmlData, options) {
|
|
|
262
264
|
tagName = tagName.substr(colonIndex+1);
|
|
263
265
|
}
|
|
264
266
|
}
|
|
265
|
-
|
|
267
|
+
|
|
266
268
|
//save text to parent node
|
|
267
269
|
if (currentNode && textData) {
|
|
268
270
|
if(currentNode.tagname !== '!xml'){
|
|
@@ -270,9 +272,9 @@ const getTraversalObj = function(xmlData, options) {
|
|
|
270
272
|
}
|
|
271
273
|
}
|
|
272
274
|
|
|
273
|
-
if(tagExp.lastIndexOf("/") === tagExp.length - 1){//selfClosing tag
|
|
274
|
-
|
|
275
|
-
if(tagName[tagName.length - 1] === "/"){ //remove trailing '/'
|
|
275
|
+
if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){//selfClosing tag
|
|
276
|
+
|
|
277
|
+
if(tagName[tagName.length - 1] === "/"){ //remove trailing '/'
|
|
276
278
|
tagName = tagName.substr(0, tagName.length - 1);
|
|
277
279
|
tagExp = tagName;
|
|
278
280
|
}else{
|
|
@@ -285,7 +287,7 @@ const getTraversalObj = function(xmlData, options) {
|
|
|
285
287
|
}
|
|
286
288
|
currentNode.addChild(childNode);
|
|
287
289
|
}else{//opening tag
|
|
288
|
-
|
|
290
|
+
|
|
289
291
|
const childNode = new xmlNode( tagName, currentNode );
|
|
290
292
|
if (options.stopNodes.length && options.stopNodes.includes(childNode.tagname)) {
|
|
291
293
|
childNode.startIndex=closeIndex;
|
|
@@ -308,6 +310,7 @@ const getTraversalObj = function(xmlData, options) {
|
|
|
308
310
|
|
|
309
311
|
function closingIndexForOpeningTag(data, i){
|
|
310
312
|
let attrBoundary;
|
|
313
|
+
let tagExp = "";
|
|
311
314
|
for (let index = i; index < data.length; index++) {
|
|
312
315
|
let ch = data[index];
|
|
313
316
|
if (attrBoundary) {
|
|
@@ -315,8 +318,23 @@ function closingIndexForOpeningTag(data, i){
|
|
|
315
318
|
} else if (ch === '"' || ch === "'") {
|
|
316
319
|
attrBoundary = ch;
|
|
317
320
|
} else if (ch === '>') {
|
|
318
|
-
return
|
|
321
|
+
return {
|
|
322
|
+
data: tagExp,
|
|
323
|
+
index: index
|
|
324
|
+
}
|
|
325
|
+
} else if (ch === '\t') {
|
|
326
|
+
ch = " "
|
|
319
327
|
}
|
|
328
|
+
tagExp += ch;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function findClosingIndex(xmlData, str, i, errMsg){
|
|
333
|
+
const closingIndex = xmlData.indexOf(str, i);
|
|
334
|
+
if(closingIndex === -1){
|
|
335
|
+
throw new Error(errMsg)
|
|
336
|
+
}else{
|
|
337
|
+
return closingIndex + str.length - 1;
|
|
320
338
|
}
|
|
321
339
|
}
|
|
322
340
|
|