@@ -85,12 +85,8 @@ exports.validate = function (xmlData, options) {
85
85
}
86
86
87
87
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 ) ;
94
90
95
91
const nsResult = validateNameSpace ( tagName , nameSpaces ) ;
96
92
@@ -109,11 +105,9 @@ exports.validate = function (xmlData, options) {
109
105
if ( isValid === true ) {
110
106
tagFound = true ;
111
107
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 ;
117
111
}
118
112
//continue; //text may presents after self closing tag
119
113
} else {
@@ -133,11 +127,9 @@ exports.validate = function (xmlData, options) {
133
127
return getErrorObject ( 'InvalidTag' , "Closing tag '" + otg . name + "' is expected inplace of '" + tagName + "'." , getLineNumberForPosition ( xmlData , i ) ) ;
134
128
}
135
129
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 ;
141
133
}
142
134
143
135
//when there are no more tags, we reached the root level.
0 commit comments