@@ -4,10 +4,8 @@ const util = require('./util');
4
4
const buildOptions = require ( './util' ) . buildOptions ;
5
5
const xmlNode = require ( './xmlNode' ) ;
6
6
const 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*>))([^<]*)' ;
11
9
12
10
//const tagsRegx = new RegExp("<(\\/?[\\w:\\-\._]+)([^>]*)>(\\s*"+cdataRegx+")*([^<]+)?","g");
13
11
//const tagsRegx = new RegExp("<(\\/?)((\\w*:)?([\\w:\\-\._]+))([^>]*)>([^<]*)("+cdataRegx+"([^<]*))*([^<]+)?","g");
@@ -81,14 +79,12 @@ const getTraversalObj = function(xmlData, options) {
81
79
let tag = tagsRegx . exec ( xmlData ) ;
82
80
let nextTag = tagsRegx . exec ( xmlData ) ;
83
81
while ( tag ) {
84
- //console.log(tag)
85
82
const tagType = checkForTagType ( tag ) ;
86
- //console.log(tagType)
87
83
88
84
if ( tagType === TagType . CLOSING ) {
89
85
//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 ) ;
92
88
}
93
89
if ( options . stopNodes . length && options . stopNodes . includes ( currentNode . tagname ) ) {
94
90
currentNode . child = [ ]
@@ -105,29 +101,29 @@ const getTraversalObj = function(xmlData, options) {
105
101
//for backtracking
106
102
currentNode . val = util . getValue ( currentNode . val ) + options . cdataPositionChar ;
107
103
//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 ) ;
110
106
}
111
107
} else {
112
- currentNode . val = ( currentNode . val || '' ) + ( tag [ 3 ] || '' ) + processTagValue ( tag [ 22 ] , options ) ;
108
+ currentNode . val = ( currentNode . val || '' ) + ( tag [ 3 ] || '' ) + processTagValue ( tag [ 14 ] , options ) ;
113
109
}
114
110
} 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 ) ;
117
113
}
118
114
119
115
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 ) {
121
117
tag [ 8 ] = tag [ 8 ] . substr ( 0 , tag [ 8 ] . length - 1 ) ;
122
- } */
118
+ }
123
119
childNode . attrsMap = buildAttributesMap ( tag [ 8 ] , options ) ;
124
120
currentNode . addChild ( childNode ) ;
125
121
} else {
126
122
//TagType.OPENING
127
123
const childNode = new xmlNode (
128
124
options . ignoreNameSpace ? tag [ 7 ] : tag [ 5 ] ,
129
125
currentNode ,
130
- processTagValue ( tag [ 22 ] , options )
126
+ processTagValue ( tag [ 14 ] , options )
131
127
) ;
132
128
if ( options . stopNodes . length && options . stopNodes . includes ( childNode . tagname ) ) {
133
129
childNode . startIndex = tag . index + tag [ 1 ] . length
@@ -159,9 +155,9 @@ function processTagValue(val, options) {
159
155
function checkForTagType ( match ) {
160
156
if ( match [ 4 ] === ']]>' ) {
161
157
return TagType . CDATA ;
162
- } else if ( match [ 18 ] === '/' ) {
158
+ } else if ( match [ 10 ] === '/' ) {
163
159
return TagType . CLOSING ;
164
- } else if ( match [ 16 ] === '/' ) {
160
+ } else if ( typeof match [ 8 ] !== 'undefined' && match [ 8 ] . substr ( match [ 8 ] . length - 1 ) === '/' ) {
165
161
return TagType . SELF ;
166
162
} else {
167
163
return TagType . OPENING ;
0 commit comments