Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions spec/data_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,25 @@ describe("XMLParser", function() {
expect(result).toEqual(expected);
});

it("should parse XML when namespaced ignored", function() {
const xmlData = `<a:b>c</a:b><a:d/><a:e atr="sasa" boolean>`;
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 = `<tag><![CDATA[undefined]]><nested>undefined</nested></tag>`;
const expected = {
Expand Down
4 changes: 3 additions & 1 deletion src/xmlstr2xmlnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down