Example #1
0
func (d *XmlDoc) XPath(xpathExpr string) *XPathResult {
	context := C.xmlXPathNewContext(d.Ptr)
	defer C.xmlXPathFreeContext(context)

	result := C.xmlXPathEvalExpression(stringToXmlChar(xpathExpr), context)

	fmt.Println("XPath: ", xpathExpr, " Type: ", result._type, " Result: ", result)

	return &XPathResult{ptr: result}
}
Example #2
0
// xmlXPathEvalExpression shim around the libxml2 function of the same name
func (xp *Xp) xmlXPathEvalExpression(context *C.xmlNode, path string) (xmlXPathObject *C.xmlXPathObject) {
	if context == nil {
		context = C.xmlDocGetRootElement(xp.doc)
	}
	C.xmlXPathSetContextNode(context, xp.xpathCtx)

	Cpath := unsafe.Pointer(C.CString(path))
	defer C.free(Cpath)
	xmlXPathObject = C.xmlXPathEvalExpression((*C.xmlChar)(Cpath), xp.xpathCtx)
	return
}
Example #3
0
func (n *XmlNode) XPath(xpathExpr string) *XPathResult {
	context := C.xmlXPathNewContext((C.xmlDocPtr)(unsafe.Pointer(n.Ptr.doc)))
	context.node = n.Ptr
	defer C.xmlXPathFreeContext(context)

	result := C.xmlXPathEvalExpression(stringToXmlChar(xpathExpr), context)

	fmt.Println("XPath: ", xpathExpr, " Type: ", result._type, " Result: ", result)

	return &XPathResult{ptr: result}
}
Example #4
0
// C14n Canonicalise the node using the SAML specified exclusive method
// Very slow on large documents with node != nil
func (xp *Xp) C14n(node *C.xmlNode) string {
	var buffer *C.xmlChar
	var nodeset *C.xmlNodeSet

	if node != nil {
		C.xmlXPathSetContextNode(node, xp.xpathCtx)
		xpathObj := C.xmlXPathEvalExpression(exclc14nxpath, xp.xpathCtx)
		defer C.xmlXPathFreeObject(xpathObj)
		nodeset = xpathObj.nodesetval
		//fmt.Printf("%+v\n", nodeset)
	}

	C.xmlC14NDocDumpMemory(xp.doc, nodeset, C.XML_C14N_EXCLUSIVE_1_0, nil, 0, &buffer)
	defer C.free(unsafe.Pointer(buffer))
	p := (*C.char)(unsafe.Pointer(buffer))
	return C.GoString(p)
}
Example #5
0
// xmlXPathEvalExpression
func (ctx *XPathContext) EvalExpression(str string) *XPathObject {
	ptr := C.CString(str)
	defer C.free_string(ptr)
	return makeXpathObj(C.xmlXPathEvalExpression(C.to_xmlcharptr(ptr), ctx.Ptr))
}