diff --git a/Sources/Element.swift b/Sources/Element.swift index 5340189..fd6a7c6 100644 --- a/Sources/Element.swift +++ b/Sources/Element.swift @@ -73,6 +73,10 @@ open class XMLElement: XMLNode { } return value } + + open func updateAttr(_ name: String, value: String) { + _ = xmlSetProp(cNode, name, value) + } // MARK: - Accessing Children diff --git a/Tests/XMLTests.swift b/Tests/XMLTests.swift index 4325c40..d7b2f02 100644 --- a/Tests/XMLTests.swift +++ b/Tests/XMLTests.swift @@ -89,4 +89,11 @@ class XMLTests: XCTestCase { let authorElements = authlistElement?.children(staticTag: "author") XCTAssertEqual(authorElements?.count, 5, "should have 5 elements") } + + func testUpdateAttribute() { + let loc = document.root!.firstChild(staticTag: "header")!.firstChild(staticTag: "prevlocs")!.firstChild(tag: "loc")! + XCTAssertEqual(loc.attr("href"), "http://www.w3.org/TR/2008/PER-xml-20080205/") + loc.updateAttr("href", value: "http://www.w3.org/TR/2008/PER-xml-20080277/") + XCTAssertEqual(loc.attr("href"), "http://www.w3.org/TR/2008/PER-xml-20080277/") + } }