예제 #1
0
파일: node.go 프로젝트: jbowtie/gokogiri
func (xmlNode *XmlNode) serialize(format SerializationOption, encoding, outputBuffer []byte) ([]byte, int) {
	nodePtr := unsafe.Pointer(xmlNode.Ptr)
	var encodingPtr unsafe.Pointer
	if len(encoding) == 0 {
		encoding = xmlNode.Document.OutputEncoding()
	}
	if len(encoding) > 0 {
		encodingPtr = unsafe.Pointer(&(encoding[0]))
	} else {
		encodingPtr = nil
	}

	wbufferMutex.Lock()
	defer wbufferMutex.Unlock()
	if outputBuffer == nil {
		outputBuffer = make([]byte, 0)
	}
	wbuffer = &WriteBuffer{Node: xmlNode, Buffer: outputBuffer}

	ret := int(C.xmlSaveNode(nodePtr, encodingPtr, C.int(format)))
	if ret < 0 {
		panic("output error in xml node serialization: " + strconv.Itoa(ret))
	}
	b, o := wbuffer.Buffer, wbuffer.Offset
	wbuffer = nil

	return b, o
}
예제 #2
0
func (xmlNode *XmlNode) serialize(format SerializationOption, encoding, outputBuffer []byte) ([]byte, int) {
	nodePtr := unsafe.Pointer(xmlNode.Ptr)
	var encodingPtr unsafe.Pointer
	if len(encoding) == 0 {
		encoding = xmlNode.Document.OutputEncoding()
	}
	if len(encoding) > 0 {
		encodingPtr = unsafe.Pointer(&(encoding[0]))
	} else {
		encodingPtr = nil
	}

	wbuffer := &WriteBuffer{Node: xmlNode, Buffer: outputBuffer}
	wbufferPtr := unsafe.Pointer(wbuffer)

	ret := int(C.xmlSaveNode(wbufferPtr, nodePtr, encodingPtr, C.int(format)))
	if ret < 0 {
		panic("output error in xml node serialization: " + strconv.Itoa(ret))
		return nil, 0
	}

	return wbuffer.Buffer, wbuffer.Offset
}
예제 #3
0
func (xmlNode *XmlNode) serialize(format int, encoding, outputBuffer []byte) ([]byte, int) {
	nodePtr := unsafe.Pointer(xmlNode.Ptr)
	var encodingPtr unsafe.Pointer
	if len(encoding) == 0 {
		encoding = xmlNode.Document.OutputEncoding()
	}
	if len(encoding) > 0 {
		encodingPtr = unsafe.Pointer(&(encoding[0]))
	} else {
		encodingPtr = nil
	}

	wbuffer := &WriteBuffer{Node: xmlNode, Buffer: outputBuffer}
	wbufferPtr := unsafe.Pointer(wbuffer)

	format |= XML_SAVE_FORMAT
	ret := int(C.xmlSaveNode(wbufferPtr, nodePtr, encodingPtr, C.int(format)))
	if ret < 0 {
		fmt.Println("output error!!!")
		return nil, 0
	}

	return wbuffer.Buffer, wbuffer.Offset
}