@@ -168,10 +168,12 @@ function buildAttributesMap(attrStr, options) {
168168}
169169
170170const getTraversalObj = function ( xmlData , options ) {
171+ xmlData = xmlData . replace ( / ( \r \n ) | \n / , " " ) ;
171172 options = buildOptions ( options , defaultOptions , props ) ;
172173 const xmlObj = new xmlNode ( '!xml' ) ;
173174 let currentNode = xmlObj ;
174175 let textData = "" ;
176+
175177//function match(xmlData){
176178 for ( let i = 0 ; i < xmlData . length ; i ++ ) {
177179 const ch = xmlData [ i ] ;
@@ -246,9 +248,9 @@ const getTraversalObj = function(xmlData, options) {
246248
247249 i = closeIndex + 2 ;
248250 } else { //Opening tag
249- const closeIndex = closingIndexForOpeningTag ( xmlData , i )
250- //const closeIndex = xmlData.indexOf(">",i) ;
251- let tagExp = xmlData . substring ( i + 1 , closeIndex ) ;
251+ const result = closingIndexForOpeningTag ( xmlData , i + 1 )
252+ let tagExp = result . data ;
253+ const closeIndex = result . index ;
252254 const separatorIndex = tagExp . indexOf ( " " ) ;
253255 let tagName = tagExp ;
254256 if ( separatorIndex !== - 1 ) {
@@ -308,15 +310,22 @@ const getTraversalObj = function(xmlData, options) {
308310
309311function closingIndexForOpeningTag ( data , i ) {
310312 let attrBoundary ;
313+ let tagExp = "" ;
311314 for ( let index = i ; index < data . length ; index ++ ) {
312315 let ch = data [ index ] ;
313316 if ( attrBoundary ) {
314317 if ( ch === attrBoundary ) attrBoundary = "" ; //reset
315318 } else if ( ch === '"' || ch === "'" ) {
316319 attrBoundary = ch ;
317320 } else if ( ch === '>' ) {
318- return index
321+ return {
322+ data : tagExp ,
323+ index : index
324+ }
325+ } else if ( ch === '\t' ) {
326+ ch = " "
319327 }
328+ tagExp += ch ;
320329 }
321330}
322331
0 commit comments