Beispiel #1
0
func (xmlNode *XmlNode) addNextSibling(node Node) (err error) {
	nodeType := node.NodeType()
	if nodeType == XML_DOCUMENT_NODE || nodeType == XML_HTML_DOCUMENT_NODE {
		err = ERR_CANNOT_MAKE_DUCMENT_AS_CHILD
		return
	}
	nodePtr := node.NodePtr()
	if xmlNode.NodePtr() == nodePtr {
		return
	}
	ret := xmlNode.isAccestor(nodePtr)
	if ret < 0 {
		return
	} else if ret == 0 {
		if !xmlNode.Document.RemoveUnlinkedNode(nodePtr) {
			C.xmlUnlinkNodeWithCheck((*C.xmlNode)(nodePtr))
		}
		C.xmlAddNextSibling(xmlNode.Ptr, (*C.xmlNode)(nodePtr))
	} else if ret > 0 {
		node.Remove()
	}
	/*
		childPtr := C.xmlAddNextSibling(xmlNode.Ptr, (*C.xmlNode)(nodePtr))
		if nodeType == XML_TEXT_NODE && childPtr != (*C.xmlNode)(nodePtr) {
			//check the retured pointer
			//if it is not the text node just added, it means that the text node is freed because it has merged into other nodes
			//then we should invalid this node, because we do not want to have a dangling pointer
			//node.Remove()
		}
	*/
	return
}
Beispiel #2
0
func (xmlNode *XmlNode) ResetChildren() {
	var p unsafe.Pointer
	for childPtr := xmlNode.Ptr.children; childPtr != nil; {
		nextPtr := childPtr.next
		p = unsafe.Pointer(childPtr)
		C.xmlUnlinkNodeWithCheck((*C.xmlNode)(p))
		xmlNode.Document.AddUnlinkedNode(p)
		childPtr = nextPtr
	}
}
Beispiel #3
0
func (xmlNode *XmlNode) addNextSibling(node Node) (err error) {
	nodeType := node.NodeType()
	if nodeType == XML_DOCUMENT_NODE || nodeType == XML_HTML_DOCUMENT_NODE {
		err = ERR_CANNOT_MAKE_DUCMENT_AS_CHILD
		return
	}
	nodePtr := node.NodePtr()
	if xmlNode.NodePtr() == nodePtr {
		return
	}
	ret := xmlNode.isAccestor(nodePtr)
	if ret < 0 {
		return
	} else if ret == 0 {
		if !xmlNode.Document.RemoveUnlinkedNode(nodePtr) {
			C.xmlUnlinkNodeWithCheck((*C.xmlNode)(nodePtr))
		}
		C.xmlAddNextSibling(xmlNode.Ptr, (*C.xmlNode)(nodePtr))
	} else if ret > 0 {
		node.Remove()
	}
	return
}
Beispiel #4
0
func (xmlNode *XmlNode) Unlink() {
	if int(C.xmlUnlinkNodeWithCheck(xmlNode.Ptr)) != 0 {
		xmlNode.Document.AddUnlinkedNode(unsafe.Pointer(xmlNode.Ptr))
	}
}