diff --git a/Sources/Kanna.swift b/Sources/Kanna.swift index d52f278..f1afb1d 100755 --- a/Sources/Kanna.swift +++ b/Sources/Kanna.swift @@ -228,6 +228,7 @@ public protocol XMLElement: SearchableNode { func addPrevSibling(_ node: XMLElement) func addNextSibling(_ node: XMLElement) func removeChild(_ node: XMLElement) + func cloneNode() -> XMLElement? } /** diff --git a/Sources/libxmlHTMLNode.swift b/Sources/libxmlHTMLNode.swift index 7634354..cbd66cd 100755 --- a/Sources/libxmlHTMLNode.swift +++ b/Sources/libxmlHTMLNode.swift @@ -237,6 +237,19 @@ internal final class libxmlHTMLNode: XMLElement { xmlUnlinkNode(node.nodePtr) xmlAddChild(nodePtr, node.nodePtr) } + + func cloneNode() -> XMLElement? { + var new_node: xmlNodePtr? = nil + if let string = toHTML { + xmlParseInNodeContext(nodePtr, string, Int32(string.characters.count), 0, &new_node); + if new_node != nil { + xmlAddNextSibling(nodePtr, new_node) + return libxmlHTMLNode(docPtr: docPtr!, node: new_node!) + } + } + return nil + } + func removeChild(_ node: XMLElement) {