fast-xml-parser 4.0.0-beta.7 → 4.0.0-beta.8
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 +3 -0
- package/package.json +2 -1
- package/src/xmlparser/OrderedObjParser.js +13 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.
|
|
2
2
|
|
|
3
|
+
** 4.0.0-beta.8 / 2021-12-13**
|
|
4
|
+
* call tagValueProcessor for stop nodes
|
|
5
|
+
|
|
3
6
|
** 4.0.0-beta.7 / 2021-12-09**
|
|
4
7
|
* fix Validator bug when an attribute has no value but '=' only
|
|
5
8
|
* XML Builder should suppress unpaired tags by default.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-xml-parser",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.8",
|
|
4
4
|
"description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
|
|
5
5
|
"main": "./src/fxp.js",
|
|
6
6
|
"scripts": {
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@babel/preset-env": "^7.13.10",
|
|
48
48
|
"@babel/register": "^7.13.8",
|
|
49
49
|
"babel-loader": "^8.2.2",
|
|
50
|
+
"cytorus": "^0.2.9",
|
|
50
51
|
"eslint": "^8.3.0",
|
|
51
52
|
"he": "^1.2.0",
|
|
52
53
|
"jasmine": "^3.6.4",
|
|
@@ -72,14 +72,15 @@ function addExternalEntities(externalEntities){
|
|
|
72
72
|
* @param {boolean} dontTrim
|
|
73
73
|
* @param {boolean} hasAttributes
|
|
74
74
|
* @param {boolean} isLeafNode
|
|
75
|
+
* @param {boolean} escapeEntities
|
|
75
76
|
*/
|
|
76
|
-
function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode) {
|
|
77
|
+
function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
|
|
77
78
|
if (val !== undefined) {
|
|
78
79
|
if (this.options.trimValues && !dontTrim) {
|
|
79
80
|
val = val.trim();
|
|
80
81
|
}
|
|
81
82
|
if(val.length > 0){
|
|
82
|
-
val = this.replaceEntitiesValue(val);
|
|
83
|
+
if(!escapeEntities) val = this.replaceEntitiesValue(val);
|
|
83
84
|
|
|
84
85
|
const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode);
|
|
85
86
|
if(newval === null || newval === undefined){
|
|
@@ -193,14 +194,7 @@ const parseXml = function(xmlData) {
|
|
|
193
194
|
}
|
|
194
195
|
|
|
195
196
|
if(currentNode){
|
|
196
|
-
textData = this.
|
|
197
|
-
, currentNode.tagname
|
|
198
|
-
, jPath
|
|
199
|
-
,false
|
|
200
|
-
, currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false
|
|
201
|
-
, Object.keys(currentNode.child).length === 0);
|
|
202
|
-
if(textData !== undefined && textData !== "") currentNode.add(this.options.textNodeName, textData);
|
|
203
|
-
textData = "";
|
|
197
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
204
198
|
}
|
|
205
199
|
|
|
206
200
|
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
@@ -266,14 +260,7 @@ const parseXml = function(xmlData) {
|
|
|
266
260
|
if (currentNode && textData) {
|
|
267
261
|
if(currentNode.tagname !== '!xml'){
|
|
268
262
|
//when nested tag is found
|
|
269
|
-
textData = this.
|
|
270
|
-
, currentNode.tagname
|
|
271
|
-
, jPath
|
|
272
|
-
, false
|
|
273
|
-
, currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false
|
|
274
|
-
, false);
|
|
275
|
-
if(textData !== undefined && textData !== "") currentNode.add(this.options.textNodeName, textData);
|
|
276
|
-
textData = "";
|
|
263
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
|
|
277
264
|
}
|
|
278
265
|
}
|
|
279
266
|
|
|
@@ -306,6 +293,10 @@ const parseXml = function(xmlData) {
|
|
|
306
293
|
if(tagName !== tagExp && attrExpPresent){
|
|
307
294
|
childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
|
|
308
295
|
}
|
|
296
|
+
if(tagContent) {
|
|
297
|
+
tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
|
|
298
|
+
}
|
|
299
|
+
|
|
309
300
|
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
310
301
|
childNode.add(this.options.textNodeName, tagContent);
|
|
311
302
|
|
|
@@ -369,14 +360,16 @@ const replaceEntitiesValue = function(val){
|
|
|
369
360
|
}
|
|
370
361
|
return val;
|
|
371
362
|
}
|
|
372
|
-
function saveTextToParentTag(textData, currentNode, jPath) {
|
|
363
|
+
function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
|
|
373
364
|
if (textData) { //store previously collected data as textNode
|
|
365
|
+
if(isLeafNode === undefined) isLeafNode = Object.keys(currentNode.child).length === 0
|
|
366
|
+
|
|
374
367
|
textData = this.parseTextData(textData,
|
|
375
368
|
currentNode.tagname,
|
|
376
369
|
jPath,
|
|
377
370
|
false,
|
|
378
371
|
currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false,
|
|
379
|
-
|
|
372
|
+
isLeafNode);
|
|
380
373
|
|
|
381
374
|
if (textData !== undefined && textData !== "")
|
|
382
375
|
currentNode.add(this.options.textNodeName, textData);
|