@@ -414,6 +414,17 @@ const parseXml = function (xmlData) {
414414 this . addChild ( currentNode , childNode , jPath , startIndex ) ;
415415 jPath = jPath . substr ( 0 , jPath . lastIndexOf ( "." ) ) ;
416416 }
417+ else if ( this . options . unpairedTags . indexOf ( tagName ) !== - 1 ) { //unpaired tag
418+ const childNode = new xmlNode ( tagName ) ;
419+ if ( tagName !== tagExp && attrExpPresent ) {
420+ childNode [ ":@" ] = this . buildAttributesMap ( tagExp , jPath ) ;
421+ }
422+ this . addChild ( currentNode , childNode , jPath , startIndex ) ;
423+ jPath = jPath . substr ( 0 , jPath . lastIndexOf ( "." ) ) ;
424+ i = result . closeIndex ;
425+ // Continue to next iteration without changing currentNode
426+ continue ;
427+ }
417428 //opening tag
418429 else {
419430 const childNode = new xmlNode ( tagName ) ;
@@ -535,19 +546,19 @@ const replaceEntitiesValue = function (val, tagName, jPath) {
535546}
536547
537548
538- function saveTextToParentTag ( textData , currentNode , jPath , isLeafNode ) {
549+ function saveTextToParentTag ( textData , parentNode , jPath , isLeafNode ) {
539550 if ( textData ) { //store previously collected data as textNode
540- if ( isLeafNode === undefined ) isLeafNode = currentNode . child . length === 0
551+ if ( isLeafNode === undefined ) isLeafNode = parentNode . child . length === 0
541552
542553 textData = this . parseTextData ( textData ,
543- currentNode . tagname ,
554+ parentNode . tagname ,
544555 jPath ,
545556 false ,
546- currentNode [ ":@" ] ? Object . keys ( currentNode [ ":@" ] ) . length !== 0 : false ,
557+ parentNode [ ":@" ] ? Object . keys ( parentNode [ ":@" ] ) . length !== 0 : false ,
547558 isLeafNode ) ;
548559
549560 if ( textData !== undefined && textData !== "" )
550- currentNode . add ( this . options . textNodeName , textData ) ;
561+ parentNode . add ( this . options . textNodeName , textData ) ;
551562 textData = "" ;
552563 }
553564 return textData ;
0 commit comments