@@ -36,11 +36,11 @@ export class XmlSerializer extends XmlBaseSerializer {
3636 }
3737
3838 #buildXmlDocument (
39- normalizedBom : SimpleXml . Element
39+ rootElement : SimpleXml . Element
4040 ) : XMLDocument {
4141 const namespace = null
4242 const doc = document . implementation . createDocument ( namespace , null )
43- doc . appendChild ( this . #buildElement( normalizedBom , doc , namespace ) )
43+ doc . appendChild ( this . #buildElement( rootElement , doc , namespace ) )
4444 return doc
4545 }
4646
@@ -58,7 +58,7 @@ export class XmlSerializer extends XmlBaseSerializer {
5858 this . #setAttributes( node , element . attributes )
5959 }
6060 if ( isNotUndefined ( element . children ) ) {
61- this . #setChildren ( node , element . children , ns )
61+ this . #addChildren ( node , element . children , ns )
6262 }
6363 return node
6464 }
@@ -72,14 +72,18 @@ export class XmlSerializer extends XmlBaseSerializer {
7272 }
7373 }
7474
75- #setChildren ( node : Element , children : SimpleXml . ElementChildren , parentNS : string | null = null ) : void {
75+ #addChildren ( node : Element , children : SimpleXml . ElementChildren , parentNS : string | null = null ) : void {
76+ if ( children === undefined ) {
77+ return
78+ }
79+
7680 if ( typeof children === 'string' || typeof children === 'number' ) {
7781 node . textContent = children . toString ( )
7882 return
7983 }
8084
8185 const doc = node . ownerDocument
82- for ( const child of ( children as Iterable < SimpleXml . Comment | SimpleXml . Element > ) ) {
86+ for ( const child of children ) {
8387 if ( child . type === 'element' ) {
8488 node . appendChild ( this . #buildElement( child , doc , parentNS ) )
8589 }
0 commit comments