Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
// 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
}
Ejemplo n.º 3
0
// xmlXPathConvertBoolean
func (obj *XPathObject) ConvertBoolean() *XPathObject {
	return makeXpathObj(C.xmlXPathConvertBoolean(obj.Ptr))
}