@@ -4,10 +4,8 @@ const util = require('./util');
44const buildOptions = require ( './util' ) . buildOptions ;
55const xmlNode = require ( './xmlNode' ) ;
66const TagType = { OPENING : 1 , CLOSING : 2 , SELF : 3 , CDATA : 4 } ;
7- const attrstr_regex = '((\\s*[\\w\\-._:]+(=((\'([^\']*)\')|("([^"]*)")))?)*)\\s*' ;
8- let regx = '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|(([\\w:\\-._]*:)?([\\w:\\-._]+))' + attrstr_regex + '(\\/)?>|((\\/)(([\\w:\\-._]*:)?([\\w:\\-._]+))\\s*>))([^<]*)' ;
9- //'<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|(([\\w:\\-._]*:)?([\\w:\\-._]+))([^>]*)>|((\\/)(([\\w:\\-._]*:)?([\\w:\\-._]+))\\s*>))([^<]*)';
10-
7+ let regx =
8+ '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|(([\\w:\\-._]*:)?([\\w:\\-._]+))([^>]*)>|((\\/)(([\\w:\\-._]*:)?([\\w:\\-._]+))\\s*>))([^<]*)' ;
119
1210//const tagsRegx = new RegExp("<(\\/?[\\w:\\-\._]+)([^>]*)>(\\s*"+cdataRegx+")*([^<]+)?","g");
1311//const tagsRegx = new RegExp("<(\\/?)((\\w*:)?([\\w:\\-\._]+))([^>]*)>([^<]*)("+cdataRegx+"([^<]*))*([^<]+)?","g");
@@ -81,14 +79,12 @@ const getTraversalObj = function(xmlData, options) {
8179 let tag = tagsRegx . exec ( xmlData ) ;
8280 let nextTag = tagsRegx . exec ( xmlData ) ;
8381 while ( tag ) {
84- //console.log(tag)
8582 const tagType = checkForTagType ( tag ) ;
86- //console.log(tagType)
8783
8884 if ( tagType === TagType . CLOSING ) {
8985 //add parsed data to parent node
90- if ( currentNode . parent && tag [ 22 ] ) {
91- currentNode . parent . val = util . getValue ( currentNode . parent . val ) + '' + processTagValue ( tag [ 22 ] , options ) ;
86+ if ( currentNode . parent && tag [ 14 ] ) {
87+ currentNode . parent . val = util . getValue ( currentNode . parent . val ) + '' + processTagValue ( tag [ 14 ] , options ) ;
9288 }
9389 if ( options . stopNodes . length && options . stopNodes . includes ( currentNode . tagname ) ) {
9490 currentNode . child = [ ]
@@ -105,29 +101,29 @@ const getTraversalObj = function(xmlData, options) {
105101 //for backtracking
106102 currentNode . val = util . getValue ( currentNode . val ) + options . cdataPositionChar ;
107103 //add rest value to parent node
108- if ( tag [ 22 ] ) {
109- currentNode . val += processTagValue ( tag [ 22 ] , options ) ;
104+ if ( tag [ 14 ] ) {
105+ currentNode . val += processTagValue ( tag [ 14 ] , options ) ;
110106 }
111107 } else {
112- currentNode . val = ( currentNode . val || '' ) + ( tag [ 3 ] || '' ) + processTagValue ( tag [ 22 ] , options ) ;
108+ currentNode . val = ( currentNode . val || '' ) + ( tag [ 3 ] || '' ) + processTagValue ( tag [ 14 ] , options ) ;
113109 }
114110 } else if ( tagType === TagType . SELF ) {
115- if ( currentNode && tag [ 22 ] ) {
116- currentNode . val = util . getValue ( currentNode . val ) + '' + processTagValue ( tag [ 22 ] , options ) ;
111+ if ( currentNode && tag [ 14 ] ) {
112+ currentNode . val = util . getValue ( currentNode . val ) + '' + processTagValue ( tag [ 14 ] , options ) ;
117113 }
118114
119115 const childNode = new xmlNode ( options . ignoreNameSpace ? tag [ 7 ] : tag [ 5 ] , currentNode , '' ) ;
120- /* if (tag[8] && tag[8].length > 0) {
116+ if ( tag [ 8 ] && tag [ 8 ] . length > 0 ) {
121117 tag [ 8 ] = tag [ 8 ] . substr ( 0 , tag [ 8 ] . length - 1 ) ;
122- } */
118+ }
123119 childNode . attrsMap = buildAttributesMap ( tag [ 8 ] , options ) ;
124120 currentNode . addChild ( childNode ) ;
125121 } else {
126122 //TagType.OPENING
127123 const childNode = new xmlNode (
128124 options . ignoreNameSpace ? tag [ 7 ] : tag [ 5 ] ,
129125 currentNode ,
130- processTagValue ( tag [ 22 ] , options )
126+ processTagValue ( tag [ 14 ] , options )
131127 ) ;
132128 if ( options . stopNodes . length && options . stopNodes . includes ( childNode . tagname ) ) {
133129 childNode . startIndex = tag . index + tag [ 1 ] . length
@@ -159,9 +155,9 @@ function processTagValue(val, options) {
159155function checkForTagType ( match ) {
160156 if ( match [ 4 ] === ']]>' ) {
161157 return TagType . CDATA ;
162- } else if ( match [ 18 ] === '/' ) {
158+ } else if ( match [ 10 ] === '/' ) {
163159 return TagType . CLOSING ;
164- } else if ( match [ 16 ] === '/' ) {
160+ } else if ( typeof match [ 8 ] !== 'undefined' && match [ 8 ] . substr ( match [ 8 ] . length - 1 ) === '/' ) {
165161 return TagType . SELF ;
166162 } else {
167163 return TagType . OPENING ;
0 commit comments