// 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 }
// 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) }