fast-xml-parser 3.17.0 → 3.17.4
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/README.md +20 -18
- package/package.json +13 -9
- package/src/parser.js +2 -2
- package/src/xmlstr2xmlnode.js +43 -33
package/README.md
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
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
|
+

|
|
5
18
|
|
|
19
|
+
<a href="https://opencollective.com/fast-xml-parser/donate" target="_blank">
|
|
20
|
+
<img src="https://opencollective.com/fast-xml-parser/donate/button@2x.png?color=blue" width=200 />
|
|
21
|
+
</a>
|
|
22
|
+
<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>
|
|
23
|
+
<a href="https://paypal.me/naturalintelligence"> <img src="static/img/support_paypal.svg" alt="Stubmatic donate button" width="200"/></a>
|
|
6
24
|
|
|
7
25
|
## Users
|
|
8
26
|
List of some applications/projects using Fast XML Parser. (Raise an issue to submit yours)
|
|
@@ -64,25 +82,8 @@ List of some applications/projects using Fast XML Parser. (Raise an issue to sub
|
|
|
64
82
|
|
|
65
83
|
|
|
66
84
|
|
|
67
|
-
### Join this project as collaborator / maintainer.
|
|
68
85
|
|
|
69
86
|
|
|
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
87
|
### Main Features
|
|
87
88
|
|
|
88
89
|
<img align="right" src="static/img/fxp_logo.png" width="180px" alt="FXP logo"/>
|
|
@@ -313,6 +314,7 @@ With the correct options, you can get the almost original XML without losing any
|
|
|
313
314
|
- [शब्दावली (shabdawali)](https://github.com/amitguptagwl/shabdawali) : Amazing human like typing effects beyond your imagination.
|
|
314
315
|
|
|
315
316
|
|
|
317
|
+
|
|
316
318
|
## Contributors
|
|
317
319
|
|
|
318
320
|
This project exists thanks to [all](graphs/contributors) the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-xml-parser",
|
|
3
|
-
"version": "3.17.
|
|
3
|
+
"version": "3.17.4",
|
|
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": {
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
],
|
|
71
71
|
"license": "MIT",
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@babel/core": "^7.
|
|
74
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
75
|
-
"@babel/preset-env": "^7.
|
|
76
|
-
"@babel/register": "^7.
|
|
77
|
-
"babel-loader": "^8.0
|
|
73
|
+
"@babel/core": "^7.10.2",
|
|
74
|
+
"@babel/plugin-transform-runtime": "^7.10.1",
|
|
75
|
+
"@babel/preset-env": "^7.10.2",
|
|
76
|
+
"@babel/register": "^7.10.1",
|
|
77
|
+
"babel-loader": "^8.1.0",
|
|
78
78
|
"eslint": "^5.16.0",
|
|
79
79
|
"he": "^1.2.0",
|
|
80
80
|
"http-server": "^0.12.3",
|
|
@@ -83,8 +83,12 @@
|
|
|
83
83
|
"nimnjs": "^1.3.2",
|
|
84
84
|
"prettier": "^1.19.1",
|
|
85
85
|
"publish-please": "^5.5.1",
|
|
86
|
-
"webpack": "^4.
|
|
87
|
-
"webpack-cli": "^3.3.
|
|
86
|
+
"webpack": "^4.43.0",
|
|
87
|
+
"webpack-cli": "^3.3.11"
|
|
88
88
|
},
|
|
89
|
-
"typings": "src/parser.d.ts"
|
|
89
|
+
"typings": "src/parser.d.ts",
|
|
90
|
+
"funding": {
|
|
91
|
+
"type": "paypal",
|
|
92
|
+
"url": "https://paypal.me/naturalintelligence"
|
|
93
|
+
}
|
|
90
94
|
}
|
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)|\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,29 +209,21 @@ 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
|
-
//save previous value to the parent node
|
|
226
|
-
/* if(currentNode){
|
|
227
|
-
if(currentNode.val){
|
|
228
|
-
currentNode.val = util.getValue(currentNode.val) + '' + processTagValue2(currentNode.tagname, textData , options);
|
|
229
|
-
}else{
|
|
230
|
-
currentNode.val = processTagValue2(currentNode.tagname, textData , options);
|
|
231
|
-
}
|
|
232
|
-
} */
|
|
233
227
|
//considerations
|
|
234
228
|
//1. CDATA will always have parent node
|
|
235
229
|
//2. A tag with CDATA is not a leaf node so it's value would be string type.
|
|
@@ -251,16 +245,16 @@ const getTraversalObj = function(xmlData, options) {
|
|
|
251
245
|
} else {
|
|
252
246
|
currentNode.val = (currentNode.val || '') + (tagExp || '');
|
|
253
247
|
}
|
|
254
|
-
|
|
248
|
+
|
|
255
249
|
i = closeIndex + 2;
|
|
256
250
|
}else {//Opening tag
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
251
|
+
const result = closingIndexForOpeningTag(xmlData, i+1)
|
|
252
|
+
let tagExp = result.data;
|
|
253
|
+
const closeIndex = result.index;
|
|
260
254
|
const separatorIndex = tagExp.indexOf(" ");
|
|
261
255
|
let tagName = tagExp;
|
|
262
256
|
if(separatorIndex !== -1){
|
|
263
|
-
tagName = tagExp.substr(0, separatorIndex);
|
|
257
|
+
tagName = tagExp.substr(0, separatorIndex).trimRight();
|
|
264
258
|
tagExp = tagExp.substr(separatorIndex + 1);
|
|
265
259
|
}
|
|
266
260
|
|
|
@@ -270,7 +264,7 @@ const getTraversalObj = function(xmlData, options) {
|
|
|
270
264
|
tagName = tagName.substr(colonIndex+1);
|
|
271
265
|
}
|
|
272
266
|
}
|
|
273
|
-
|
|
267
|
+
|
|
274
268
|
//save text to parent node
|
|
275
269
|
if (currentNode && textData) {
|
|
276
270
|
if(currentNode.tagname !== '!xml'){
|
|
@@ -278,9 +272,9 @@ const getTraversalObj = function(xmlData, options) {
|
|
|
278
272
|
}
|
|
279
273
|
}
|
|
280
274
|
|
|
281
|
-
if(tagExp.lastIndexOf("/") === tagExp.length - 1){//selfClosing tag
|
|
282
|
-
|
|
283
|
-
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 '/'
|
|
284
278
|
tagName = tagName.substr(0, tagName.length - 1);
|
|
285
279
|
tagExp = tagName;
|
|
286
280
|
}else{
|
|
@@ -293,7 +287,7 @@ const getTraversalObj = function(xmlData, options) {
|
|
|
293
287
|
}
|
|
294
288
|
currentNode.addChild(childNode);
|
|
295
289
|
}else{//opening tag
|
|
296
|
-
|
|
290
|
+
|
|
297
291
|
const childNode = new xmlNode( tagName, currentNode );
|
|
298
292
|
if (options.stopNodes.length && options.stopNodes.includes(childNode.tagname)) {
|
|
299
293
|
childNode.startIndex=closeIndex;
|
|
@@ -316,6 +310,7 @@ const getTraversalObj = function(xmlData, options) {
|
|
|
316
310
|
|
|
317
311
|
function closingIndexForOpeningTag(data, i){
|
|
318
312
|
let attrBoundary;
|
|
313
|
+
let tagExp = "";
|
|
319
314
|
for (let index = i; index < data.length; index++) {
|
|
320
315
|
let ch = data[index];
|
|
321
316
|
if (attrBoundary) {
|
|
@@ -323,8 +318,23 @@ function closingIndexForOpeningTag(data, i){
|
|
|
323
318
|
} else if (ch === '"' || ch === "'") {
|
|
324
319
|
attrBoundary = ch;
|
|
325
320
|
} else if (ch === '>') {
|
|
326
|
-
return
|
|
321
|
+
return {
|
|
322
|
+
data: tagExp,
|
|
323
|
+
index: index
|
|
324
|
+
}
|
|
325
|
+
} else if (ch === '\t') {
|
|
326
|
+
ch = " "
|
|
327
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;
|
|
328
338
|
}
|
|
329
339
|
}
|
|
330
340
|
|