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 d5e4ea0
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 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 @@ -109,11 +105,9 @@ exports.validate = function (xmlData, options) {
if (isValid === true) {
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]);
}
if (!options.ignoreNameSpace) {
//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) {
//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 d5e4ea0

Please sign in to comment.