diff --git a/spec/data_spec.js b/spec/data_spec.js index d542008b..2809fc1a 100644 --- a/spec/data_spec.js +++ b/spec/data_spec.js @@ -178,6 +178,25 @@ describe("XMLParser", function() { expect(result).toEqual(expected); }); + it("should parse XML when namespaced ignored", function() { + const xmlData = `c`; + const expected = { + "b" : "c", + "d" : "", + "e" : { + "@_atr": "sasa", + "@_boolean": true, + } + }; + + const result = parser.parse(xmlData, { + ignoreAttributes: false, + allowBooleanAttributes: true, + ignoreNameSpace: true, + }); + expect(result).toEqual(expected); + }); + it("should parse XML with undefined as text", function() { const xmlData = `undefined`; const expected = { diff --git a/src/xmlstr2xmlnode.js b/src/xmlstr2xmlnode.js index 87c589f6..b330d138 100644 --- a/src/xmlstr2xmlnode.js +++ b/src/xmlstr2xmlnode.js @@ -253,6 +253,7 @@ const getTraversalObj = function(xmlData, options) { const closeIndex = result.index; const separatorIndex = tagExp.indexOf(" "); let tagName = tagExp; + let shouldBuildAttributesMap = true; if(separatorIndex !== -1){ tagName = tagExp.substr(0, separatorIndex).replace(/\s\s*$/, ''); tagExp = tagExp.substr(separatorIndex + 1); @@ -262,6 +263,7 @@ const getTraversalObj = function(xmlData, options) { const colonIndex = tagName.indexOf(":"); if(colonIndex !== -1){ tagName = tagName.substr(colonIndex+1); + shouldBuildAttributesMap = tagName !== result.data.substr(colonIndex + 1); } } @@ -292,7 +294,7 @@ const getTraversalObj = function(xmlData, options) { if (options.stopNodes.length && options.stopNodes.includes(childNode.tagname)) { childNode.startIndex=closeIndex; } - if(tagName !== tagExp){ + if(tagName !== tagExp && shouldBuildAttributesMap){ childNode.attrsMap = buildAttributesMap(tagExp, options); } currentNode.addChild(childNode);