@@ -293,21 +293,23 @@ struct XMLCoderElement: Equatable {
293293// MARK: - Convenience Initializers
294294
295295extension XMLCoderElement {
296- init ( key: String , box: UnkeyedBox ) {
296+ init ( key: String , box: UnkeyedBox , attributes : [ Attribute ] = [ ] ) {
297297 if let containsChoice = box as? [ ChoiceBox ] {
298- self . init ( key: key, elements: containsChoice. map {
299- XMLCoderElement ( key: $0. key, box: $0. element)
300- } )
298+ self . init (
299+ key: key,
300+ elements: containsChoice. map { XMLCoderElement ( key: $0. key, box: $0. element) } ,
301+ attributes: attributes
302+ )
301303 } else {
302- self . init ( key: key, elements: box. map { XMLCoderElement ( key: key, box: $0) } )
304+ self . init ( key: key, elements: box. map { XMLCoderElement ( key: key, box: $0) } , attributes : attributes )
303305 }
304306 }
305307
306- init ( key: String , box: ChoiceBox ) {
307- self . init ( key: key, elements: [ XMLCoderElement ( key: box. key, box: box. element) ] )
308+ init ( key: String , box: ChoiceBox , attributes : [ Attribute ] = [ ] ) {
309+ self . init ( key: key, elements: [ XMLCoderElement ( key: box. key, box: box. element) ] , attributes : attributes )
308310 }
309311
310- init ( key: String , box: KeyedBox ) {
312+ init ( key: String , box: KeyedBox , attributes : [ Attribute ] = [ ] ) {
311313 var elements : [ XMLCoderElement ] = [ ]
312314
313315 for (key, box) in box. elements {
@@ -338,7 +340,7 @@ extension XMLCoderElement {
338340 }
339341 }
340342
341- let attributes : [ Attribute ] = box. attributes. compactMap { key, box in
343+ let attributes : [ Attribute ] = attributes + box. attributes. compactMap { key, box in
342344 guard let value = box. xmlString else {
343345 return nil
344346 }
@@ -348,30 +350,30 @@ extension XMLCoderElement {
348350 self . init ( key: key, elements: elements, attributes: attributes)
349351 }
350352
351- init ( key: String , box: SimpleBox ) {
353+ init ( key: String , box: SimpleBox , attributes : [ Attribute ] = [ ] ) {
352354 if let value = box. xmlString {
353- self . init ( key: key, stringValue: value)
355+ self . init ( key: key, stringValue: value, attributes : attributes )
354356 } else {
355- self . init ( key: key)
357+ self . init ( key: key, attributes : attributes )
356358 }
357359 }
358360
359- init ( key: String , box: Box ) {
361+ init ( key: String , box: Box , attributes : [ Attribute ] = [ ] ) {
360362 switch box {
361363 case let sharedUnkeyedBox as SharedBox < UnkeyedBox > :
362- self . init ( key: key, box: sharedUnkeyedBox. unboxed)
364+ self . init ( key: key, box: sharedUnkeyedBox. unboxed, attributes : attributes )
363365 case let sharedKeyedBox as SharedBox < KeyedBox > :
364- self . init ( key: key, box: sharedKeyedBox. unboxed)
366+ self . init ( key: key, box: sharedKeyedBox. unboxed, attributes : attributes )
365367 case let sharedChoiceBox as SharedBox < ChoiceBox > :
366- self . init ( key: key, box: sharedChoiceBox. unboxed)
368+ self . init ( key: key, box: sharedChoiceBox. unboxed, attributes : attributes )
367369 case let unkeyedBox as UnkeyedBox :
368- self . init ( key: key, box: unkeyedBox)
370+ self . init ( key: key, box: unkeyedBox, attributes : attributes )
369371 case let keyedBox as KeyedBox :
370- self . init ( key: key, box: keyedBox)
372+ self . init ( key: key, box: keyedBox, attributes : attributes )
371373 case let choiceBox as ChoiceBox :
372- self . init ( key: key, box: choiceBox)
374+ self . init ( key: key, box: choiceBox, attributes : attributes )
373375 case let simpleBox as SimpleBox :
374- self . init ( key: key, box: simpleBox)
376+ self . init ( key: key, box: simpleBox, attributes : attributes )
375377 case let box:
376378 preconditionFailure ( " Unclassified box: \( type ( of: box) ) " )
377379 }
0 commit comments