Skip to content

Commit d5e4ea0

Browse files
author
Kunal Kukreja
committed
Changed approach for adding and removing namespaces
1 parent 88c47b3 commit d5e4ea0

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/validator.js

+8-16
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,8 @@ exports.validate = function (xmlData, options) {
8585
}
8686

8787
if (!options.ignoreNameSpace) {
88-
if (result.nsArray.length > 0) {
89-
//Pushing namespaces defined in tag
90-
for (let x=0; x < result.nsArray.length; x++) {
91-
nameSpaces.push(result.nsArray[x]);
92-
}
93-
}
88+
//Pushing namespaces defined in tag
89+
Array.prototype.push.apply(nameSpaces, result.nsArray);
9490

9591
const nsResult = validateNameSpace(tagName, nameSpaces);
9692

@@ -109,11 +105,9 @@ exports.validate = function (xmlData, options) {
109105
if (isValid === true) {
110106
tagFound = true;
111107

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

136-
if (!options.ignoreNameSpace && otg.nsArray.length > 0) {
137-
//Popping namespaces defined in tag
138-
for (let x=0; x < otg.nsArray.length; x++) {
139-
nameSpaces.pop(otg.nsArray[x]);
140-
}
130+
if (!options.ignoreNameSpace) {
131+
//Removing namespaces defined in current tag
132+
nameSpaces.length -= otg.nsArray.length;
141133
}
142134

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

0 commit comments

Comments
 (0)