Skip to content

Commit

Permalink
Changed approach for adding and removing namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunal Kukreja committed Jul 5, 2020
1 parent 88c47b3 commit 986662b
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,8 @@ exports.validate = function (xmlData, options) {
}

if (!options.ignoreNameSpace) {
if (result.nsArray.length > 0) {
//Pushing namespaces defined in tag
for (let x=0; x < result.nsArray.length; x++) {
nameSpaces.push(result.nsArray[x]);
}
}
//Pushing namespaces defined in tag
Array.prototype.push.apply(nameSpaces, result.nsArray);

const nsResult = validateNameSpace(tagName, nameSpaces);

Expand All @@ -110,10 +106,8 @@ exports.validate = function (xmlData, options) {
tagFound = true;

if (!options.ignoreNameSpace && result.nsArray.length > 0) {
//Popping namespaces defined in tag
for (let x=0; x < result.nsArray.length; x++) {
nameSpaces.pop(result.nsArray[x]);
}
//Removing namespaces defined in current tag
nameSpaces.length -= result.nsArray.length;
}
//continue; //text may presents after self closing tag
} else {
Expand All @@ -133,11 +127,9 @@ exports.validate = function (xmlData, options) {
return getErrorObject('InvalidTag', "Closing tag '"+otg.name+"' is expected inplace of '"+tagName+"'.", getLineNumberForPosition(xmlData, i));
}

if (!options.ignoreNameSpace && otg.nsArray.length > 0) {
//Popping namespaces defined in tag
for (let x=0; x < otg.nsArray.length; x++) {
nameSpaces.pop(otg.nsArray[x]);
}
if (!options.ignoreNameSpace && result.nsArray.length > 0) {
//Removing namespaces defined in current tag
nameSpaces.length -= otg.nsArray.length;
}

//when there are no more tags, we reached the root level.
Expand Down

0 comments on commit 986662b

Please sign in to comment.