示例#1
0
文件: gosaml.go 项目: wayf-dk/gosaml
// Validate - Schemavalidate the document against the the schema file given in url
func (xp *Xp) SchemaValidate(url string) (errs []string, err error) {
	cSchemaNewMemParserCtxt := C.xmlSchemaNewParserCtxt((*C.char)(unsafe.Pointer(C.CString(url))))
	if cSchemaNewMemParserCtxt == nil {
		return nil, errors.New("Could not create schema parser")
	}
	defer C.xmlSchemaFreeParserCtxt(cSchemaNewMemParserCtxt)
	cSchema := C.xmlSchemaParse(cSchemaNewMemParserCtxt)
	if cSchema == nil {
		return nil, errors.New("Could not parse schema")
	}
	defer C.xmlSchemaFree(cSchema)

	validCtxt := C.xmlSchemaNewValidCtxt(cSchema)
	if validCtxt == nil {
		return nil, errors.New("Could not build validator")
	}
	defer C.xmlSchemaFreeValidCtxt(validCtxt)

	// void_libxml_error_handler is a null function - no info collected - just the final result matters - for now
	C.xmlSchemaSetValidErrors(validCtxt, (*[0]byte)(C.void_libxml_error_handler), (*[0]byte)(C.void_libxml_error_handler), nil)

	if errno := C.xmlSchemaValidateDoc(validCtxt, xp.doc); errno != 0 {
		return nil, fmt.Errorf("Document validation error %d", errno)
	}
	return nil, nil
}
示例#2
0
文件: schema.go 项目: chreble/xsd
func finaliseSchema(s *Schema) {
	C.xmlSchemaFree(s.Ptr)
}