Esempio n. 1
0
func NewDocument(version, encoding string) *Document {
	doc := C.xmlNewDoc(stringToXmlChar(version))
	if encoding != "" {
		doc.encoding = C.xmlStrdup(stringToXmlChar(encoding))
	}
	return wrapDocument(doc)
}
Esempio n. 2
0
func (x *XPathContext) evalXPath(expr *XPathExpression) (*XPathObject, error) {
	if expr == nil {
		return nil, errors.New("empty XPathExpression")
	}

	// If there is no document associated with this context,
	// then xmlXPathCompiledEval() just fails to match
	ctx := x.ptr

	if ctx.node != nil && ctx.node.doc != nil {
		ctx.doc = ctx.node.doc
	}

	if ctx.doc == nil {
		ctx.doc = C.xmlNewDoc(stringToXmlChar("1.0"))
		defer C.xmlFreeDoc(ctx.doc)
	}

	res := C.xmlXPathCompiledEval(expr.ptr, ctx)
	if res == nil {
		return nil, errors.New("empty result")
	}

	return &XPathObject{ptr: res}, nil
}
Esempio n. 3
0
// Parse SAML xml to Xp object with doc and xpath with relevant namespaces registered
func NewXp(xml []byte) *Xp {
	x := new(Xp)
	if len(xml) == 0 {
		x.doc = C.xmlNewDoc((*C.xmlChar)(unsafe.Pointer(C.CString("1.0"))))
	} else {
		x.doc = C.xmlParseMemory((*C.char)(unsafe.Pointer(&xml[0])), C.int(len(xml)))
	}
	x.xpathCtx = C.xmlXPathNewContext(x.doc)
	runtime.SetFinalizer(x, (*Xp).free)

	for _, ns := range namespaces {
		C.xmlXPathRegisterNs(x.xpathCtx, ns.prefix, ns.ns_uri)
	}
	return x
}
Esempio n. 4
0
// xmlNewDoc
func NewDoc(version string) *Document {
	ptr := C.CString(version)
	defer C.free_string(ptr)
	cdoc := C.xmlNewDoc(C.to_xmlcharptr(ptr))
	return makeDoc(cdoc)
}
Esempio n. 5
0
func XmlNewDoc(version string) unsafe.Pointer {
	cversion := cToXmlChar(C.CString(version))
	cdoc := C.xmlNewDoc(cversion)
	C.free(unsafe.Pointer(cversion))
	return unsafe.Pointer(cdoc)
}