fast-xml-parser 4.0.0-beta.4 → 4.0.0-beta.5

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 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.5 / 2021-12-04**
4
+ * fix: when a tag with name "attributes"
5
+
3
6
  ** 4.0.0-beta.4 / 2021-12-02**
4
7
  * Support HTML document parsing
5
8
  * skip stop nodes parsing when building the XML from JS object
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-xml-parser",
3
- "version": "4.0.0-beta.4",
3
+ "version": "4.0.0-beta.5",
4
4
  "description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
5
5
  "main": "./src/fxp.js",
6
6
  "scripts": {
@@ -40,7 +40,7 @@ function arrToStr(arr, options, jPath, level){
40
40
  xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
41
41
  continue;
42
42
  }
43
- const attStr = attr_to_str(tagObj.attributes, options);
43
+ const attStr = attr_to_str(tagObj[":@"], options);
44
44
  let tagStart = indentation + `<${tagName}${attStr}`;
45
45
  let tagValue = arrToStr(tagObj[tagName], options, newJPath, level + 1);
46
46
  if( (!tagValue || tagValue.length === 0) && options.suppressEmptyNode){
@@ -62,7 +62,7 @@ function propName(obj){
62
62
  const keys = Object.keys(obj);
63
63
  for (let i = 0; i < keys.length; i++) {
64
64
  const key = keys[i];
65
- if(key !== "attributes") return key;
65
+ if(key !== ":@") return key;
66
66
  }
67
67
  }
68
68
 
@@ -196,7 +196,7 @@ const parseXml = function(xmlData) {
196
196
  , currentNode.tagname
197
197
  , jPath
198
198
  ,false
199
- , currentNode.attributes ? Object.keys(currentNode.attributes).length !== 0 : false
199
+ , currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false
200
200
  , Object.keys(currentNode.child).length === 0);
201
201
  if(textData !== undefined && textData !== "") currentNode.add(this.options.textNodeName, textData);
202
202
  textData = "";
@@ -220,7 +220,7 @@ const parseXml = function(xmlData) {
220
220
  , currentNode.tagname
221
221
  , jPath
222
222
  ,false
223
- , currentNode.attributes ? Object.keys(currentNode.attributes).length !== 0 : false
223
+ , currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false
224
224
  , Object.keys(currentNode.child).length === 0);
225
225
 
226
226
  if(textData !== undefined && textData !== "") currentNode.add(this.options.textNodeName, textData);
@@ -242,7 +242,7 @@ const parseXml = function(xmlData) {
242
242
  , currentNode.tagname
243
243
  , jPath
244
244
  ,false
245
- , currentNode.attributes ? Object.keys(currentNode.attributes).length !== 0 : false
245
+ , currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false
246
246
  , Object.keys(currentNode.child).length === 0);
247
247
 
248
248
  if(textData !== undefined && textData !== "") currentNode.add(this.options.textNodeName, textData);
@@ -277,7 +277,7 @@ const parseXml = function(xmlData) {
277
277
  , currentNode.tagname
278
278
  , jPath
279
279
  , false
280
- , currentNode.attributes ? Object.keys(currentNode.attributes).length !== 0 : false
280
+ , currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false
281
281
  , false);
282
282
  if(textData !== undefined && textData !== "") currentNode.add(this.options.textNodeName, textData);
283
283
  textData = "";
@@ -311,7 +311,7 @@ const parseXml = function(xmlData) {
311
311
 
312
312
  const childNode = new xmlNode(tagName);
313
313
  if(tagName !== tagExp && attrExpPresent){
314
- childNode.attributes = this.buildAttributesMap(tagExp, jPath);
314
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
315
315
  }
316
316
  jPath = jPath.substr(0, jPath.lastIndexOf("."));
317
317
  childNode.add(this.options.textNodeName, tagContent);
@@ -330,7 +330,7 @@ const parseXml = function(xmlData) {
330
330
 
331
331
  const childNode = new xmlNode(tagName);
332
332
  if(tagName !== tagExp && attrExpPresent){
333
- childNode.attributes = this.buildAttributesMap(tagExp, jPath);
333
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
334
334
  }
335
335
  jPath = jPath.substr(0, jPath.lastIndexOf("."));
336
336
  currentNode.addChild(childNode);
@@ -341,7 +341,7 @@ const parseXml = function(xmlData) {
341
341
  this.tagsNodeStack.push(currentNode);
342
342
 
343
343
  if(tagName !== tagExp && attrExpPresent){
344
- childNode.attributes = this.buildAttributesMap(tagExp, jPath);
344
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
345
345
  }
346
346
  currentNode.addChild(childNode);
347
347
  currentNode = childNode;
@@ -37,8 +37,8 @@ function compress(arr, options, jPath){
37
37
  let val = compress(tagObj[property], options, newJpath);
38
38
  const isLeaf = isLeafTag(val, options);
39
39
 
40
- if(tagObj.attributes){
41
- assignAttributes( val, tagObj.attributes, newJpath, options);
40
+ if(tagObj[":@"]){
41
+ assignAttributes( val, tagObj[":@"], newJpath, options);
42
42
  }else if(Object.keys(val).length === 1 && val[options.textNodeName] !== undefined && !options.alwaysCreateTextNode){
43
43
  val = val[options.textNodeName];
44
44
  }else if(Object.keys(val).length === 0){
@@ -74,7 +74,7 @@ function propName(obj){
74
74
  const keys = Object.keys(obj);
75
75
  for (let i = 0; i < keys.length; i++) {
76
76
  const key = keys[i];
77
- if(key !== "attributes") return key;
77
+ if(key !== ":@") return key;
78
78
  }
79
79
  }
80
80
 
@@ -4,15 +4,15 @@ class XmlNode{
4
4
  constructor(tagname) {
5
5
  this.tagname = tagname;
6
6
  this.child = []; //nested tags, text, cdata, comments in order
7
- this.attributes = {}; //attributes map
7
+ this[":@"] = {}; //attributes map
8
8
  }
9
9
  add(key,val){
10
10
  // this.child.push( {name : key, val: val, isCdata: isCdata });
11
11
  this.child.push( {[key]: val });
12
12
  }
13
13
  addChild(node) {
14
- if(node.attributes && Object.keys(node.attributes).length > 0){
15
- this.child.push( { [node.tagname]: node.child, attributes: node.attributes });
14
+ if(node[":@"] && Object.keys(node[":@"]).length > 0){
15
+ this.child.push( { [node.tagname]: node.child, [":@"]: node[":@"] });
16
16
  }else{
17
17
  this.child.push( { [node.tagname]: node.child });
18
18
  }