File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -82,17 +82,15 @@ open class XMLElement: XMLNode {
82
82
83
83
/*!
84
84
@method addAttribute:
85
- @abstract Adds an attribute. Attributes with duplicate names are not added .
85
+ @abstract Adds an attribute. Attributes with duplicate names replace the old one .
86
86
*/
87
87
open func addAttribute( _ attribute: XMLNode ) {
88
88
guard let name = _CFXMLNodeCopyName ( attribute. _xmlNode) ? . _swiftObject else {
89
89
fatalError ( " Attributes must have a name! " )
90
90
}
91
91
92
- name. cString ( using: . utf8) !. withUnsafeBufferPointer ( ) {
93
- guard let ptr = $0. baseAddress, _CFXMLNodeHasProp ( _xmlNode, ptr) == nil else { return }
94
- addChild ( attribute)
95
- }
92
+ removeAttribute ( forName: name)
93
+ addChild ( attribute)
96
94
}
97
95
98
96
/*!
Original file line number Diff line number Diff line change @@ -233,6 +233,9 @@ class TestXMLDocument : LoopbackServerTest {
233
233
XCTAssertEqual ( element. xmlString, " <root></root> " , element. xmlString)
234
234
235
235
element. addAttribute ( attribute)
236
+ let attribute2 = XMLNode . attribute ( withName: " color " , stringValue: " #00ff00 " ) as! XMLNode
237
+ element. addAttribute ( attribute2)
238
+ XCTAssertEqual ( element. attribute ( forName: " color " ) ? . stringValue, " #00ff00 " )
236
239
237
240
let otherAttribute = XMLNode . attribute ( withName: " foo " , stringValue: " bar " ) as! XMLNode
238
241
element. addAttribute ( otherAttribute)
@@ -243,7 +246,7 @@ class TestXMLDocument : LoopbackServerTest {
243
246
}
244
247
245
248
XCTAssertEqual ( attributes. count, 2 )
246
- XCTAssertEqual ( attributes. first, attribute )
249
+ XCTAssertEqual ( attributes. first, attribute2 )
247
250
XCTAssertEqual ( attributes. last, otherAttribute)
248
251
249
252
let barAttribute = XMLNode . attribute ( withName: " bar " , stringValue: " buz " ) as! XMLNode
You can’t perform that action at this time.
0 commit comments