Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cloneNode #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/Kanna.swift
Original file line number Diff line number Diff line change
@@ -228,6 +228,7 @@ public protocol XMLElement: SearchableNode {
func addPrevSibling(_ node: XMLElement)
func addNextSibling(_ node: XMLElement)
func removeChild(_ node: XMLElement)
func cloneNode() -> XMLElement?
}

/**
13 changes: 13 additions & 0 deletions Sources/libxmlHTMLNode.swift
Original file line number Diff line number Diff line change
@@ -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) {