@@ -64,4 +64,70 @@ class XMLElementTests: XCTestCase {
6464 XCTAssert ( whitespaceElement2. isWhitespaceWithNoElements ( ) )
6565 XCTAssert ( whitespaceElement3. isWhitespaceWithNoElements ( ) )
6666 }
67+
68+ func testNestedElementWith_Namespace_Attribute( ) {
69+ typealias Attribute = XMLCoderElement . Attribute
70+ typealias Element = XMLCoderElement
71+ let nested = Element ( key: " Nested " ,
72+ elements: [
73+ Element ( key: " " ,
74+ elements: [ ] ,
75+ attributes: [
76+ Attribute ( key: " xsi:someName " , value: " nestedAttrValue " )
77+ ]
78+ ) ] ,
79+ attributes: [
80+ Attribute ( key: " xmlns:xsi " , value: " https://example.com " )
81+ ] )
82+ let inputNamespace = Attribute ( key: " xmlns " , value: " https://example.com " )
83+ let input = Element ( key: " Input " ,
84+ elements: [ nested] ,
85+ attributes: [ inputNamespace] )
86+
87+ let result = input. toXMLString (
88+ escapedCharacters: ( elements: XMLEncoder ( ) . charactersEscapedInElements,
89+ attributes: XMLEncoder ( ) . charactersEscapedInAttributes) ,
90+ formatting: [ ] ,
91+ indentation: . spaces( 4 )
92+ )
93+
94+ XCTAssertEqual ( result, """
95+ <Input xmlns= " https://example.com " ><Nested xmlns:xsi= " https://example.com " xsi:someName= " nestedAttrValue " ></Nested></Input>
96+ """ )
97+ }
98+
99+ func testNestedElementWith_Namespace_Attribute_Element( ) {
100+ typealias Attribute = XMLCoderElement . Attribute
101+ typealias Element = XMLCoderElement
102+ let nested = Element ( key: " Nested " ,
103+ elements: [
104+ Element ( key: " " ,
105+ elements: [
106+ Element ( key: " nonAttrField " ,
107+ elements: [ Element ( key: " " , stringValue: " hello " ) ] ,
108+ attributes: [ ] )
109+ ] ,
110+ attributes: [
111+ Attribute ( key: " xsi:someName " , value: " nestedAttrValue " )
112+ ]
113+ ) ] ,
114+ attributes: [
115+ Attribute ( key: " xmlns:xsi " , value: " https://example.com " )
116+ ] )
117+ let inputNamespace = Attribute ( key: " xmlns " , value: " https://example.com " )
118+ let input = Element ( key: " Input " ,
119+ elements: [ nested] ,
120+ attributes: [ inputNamespace] )
121+
122+ let result = input. toXMLString (
123+ escapedCharacters: ( elements: XMLEncoder ( ) . charactersEscapedInElements,
124+ attributes: XMLEncoder ( ) . charactersEscapedInAttributes) ,
125+ formatting: [ ] ,
126+ indentation: . spaces( 4 )
127+ )
128+
129+ XCTAssertEqual ( result, """
130+ <Input xmlns= " https://example.com " ><Nested xmlns:xsi= " https://example.com " xsi:someName= " nestedAttrValue " ><nonAttrField>hello</nonAttrField></Nested></Input>
131+ """ )
132+ }
67133}
0 commit comments