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 @@ -232,6 +232,9 @@ class TestXMLDocument : LoopbackServerTest {
232
232
XCTAssertEqual ( element. xmlString, " <root></root> " , element. xmlString)
233
233
234
234
element. addAttribute ( attribute)
235
+ let attribute2 = XMLNode . attribute ( withName: " color " , stringValue: " #00ff00 " ) as! XMLNode
236
+ element. addAttribute ( attribute2)
237
+ XCTAssertEqual ( element. attribute ( forName: " color " ) ? . stringValue, " #00ff00 " )
235
238
236
239
let otherAttribute = XMLNode . attribute ( withName: " foo " , stringValue: " bar " ) as! XMLNode
237
240
element. addAttribute ( otherAttribute)
@@ -242,7 +245,7 @@ class TestXMLDocument : LoopbackServerTest {
242
245
}
243
246
244
247
XCTAssertEqual ( attributes. count, 2 )
245
- XCTAssertEqual ( attributes. first, attribute )
248
+ XCTAssertEqual ( attributes. first, attribute2 )
246
249
XCTAssertEqual ( attributes. last, otherAttribute)
247
250
248
251
let barAttribute = XMLNode . attribute ( withName: " bar " , stringValue: " buz " ) as! XMLNode
You can’t perform that action at this time.
0 commit comments