예제 #1
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
}
예제 #2
0
파일: xpath.go 프로젝트: jbowtie/gokogiri
// Coerce the result into a boolean
func (xpath *XPath) ResultAsBoolean() (val bool, err error) {
	xpath.ResultPtr = C.xmlXPathConvertBoolean(xpath.ResultPtr)
	val = xpath.ResultPtr.boolval != 0
	return
}
예제 #3
0
// xmlXPathConvertBoolean
func (obj *XPathObject) ConvertBoolean() *XPathObject {
	return makeXpathObj(C.xmlXPathConvertBoolean(obj.Ptr))
}