示例#1
0
文件: gosaml.go 项目: wayf-dk/gosaml
// QueryNumber evaluates an xpath expressions that returns a number
func (xp *Xp) QueryNumber(context *C.xmlNode, path string) (val int) {
	var xmlXPathObject *C.xmlXPathObject
	if xmlXPathObject = xp.xmlXPathEvalExpression(context, path); xmlXPathObject == nil {
		return 0
	}
	defer C.xmlXPathFreeNodeSetList(xmlXPathObject)

	if xmlXPathObject._type == C.XPATH_NUMBER {
		val = int(xmlXPathObject.floatval)
	}
	return
}
示例#2
0
文件: gosaml.go 项目: wayf-dk/gosaml
// Query Do a xpath query with the given context
// returns a slice of nodes
func (xp *Xp) Query(context *C.xmlNode, path string) (nodes []*C.xmlNode) {
	var xmlXPathObject *C.xmlXPathObject
	if xmlXPathObject = xp.xmlXPathEvalExpression(context, path); xmlXPathObject == nil {
		return nil
	}

	defer C.xmlXPathFreeNodeSetList(xmlXPathObject)

	// curtesy of https://github.com/moovweb/gokogiri/blob/master/xpath/xpath.go#L164

	if nodesetPtr := xmlXPathObject.nodesetval; nodesetPtr != nil {
		if nodesetSize := int(nodesetPtr.nodeNr); nodesetSize > 0 {
			nodes = make([]*C.xmlNode, nodesetSize)
			for i := 0; i < nodesetSize; i++ {
				nodes[i] = C.fetchNode(nodesetPtr, C.int(i))
			}
		}
	}
	return
}
示例#3
0
// xmlXPathFreeNodeSetList
func (obj *XPathObject) FreeList() {
	C.xmlXPathFreeNodeSetList(obj.Ptr)
	obj.Ptr = nil
}