예제 #1
0
파일: xpath.go 프로젝트: jbowtie/gokogiri
// Coerce the result into a string
func (xpath *XPath) ResultAsString() (val string, err error) {
	if xpath.ReturnType() != XPATH_STRING {
		xpath.ResultPtr = C.xmlXPathConvertString(xpath.ResultPtr)
	}
	val = C.GoString((*C.char)(unsafe.Pointer(xpath.ResultPtr.stringval)))
	return
}
예제 #2
0
파일: xpath.go 프로젝트: jbowtie/gokogiri
func XPathObjectToValue(obj C.xmlXPathObjectPtr) (result interface{}) {
	rt := XPathObjectType(C.getXPathObjectType(obj))
	switch rt {
	case XPATH_NODESET, XPATH_XSLT_TREE:
		if nodesetPtr := obj.nodesetval; nodesetPtr != nil {
			if nodesetSize := int(nodesetPtr.nodeNr); nodesetSize > 0 {
				nodes := make([]unsafe.Pointer, nodesetSize)
				for i := 0; i < nodesetSize; i++ {
					nodes[i] = unsafe.Pointer(C.fetchNode(nodesetPtr, C.int(i)))
				}
				result = nodes
				return
			}
		}
		result = nil
	case XPATH_NUMBER:
		obj = C.xmlXPathConvertNumber(obj)
		result = float64(obj.floatval)
	case XPATH_BOOLEAN:
		obj = C.xmlXPathConvertBoolean(obj)
		result = obj.boolval != 0
	default:
		obj = C.xmlXPathConvertString(obj)
		result = C.GoString((*C.char)(unsafe.Pointer(obj.stringval)))
	}
	return
}
예제 #3
0
// xmlXPathConvertString
func (obj *XPathObject) ConvertString() *XPathObject {
	return makeXpathObj(C.xmlXPathConvertString(obj.Ptr))
}