static cache_entry* cache_entry_from_xsd_doc(xmlDocPtr doc) { cache_entry* entry = heap_alloc(sizeof(cache_entry)); xmlSchemaParserCtxtPtr spctx; xmlDocPtr new_doc = xmlCopyDoc(doc, 1); entry->type = SCHEMA_TYPE_XSD; entry->ref = 0; spctx = xmlSchemaNewDocParserCtxt(new_doc); if ((entry->schema = xmlSchemaParse(spctx))) { xmldoc_init(entry->schema->doc, &CLSID_DOMDocument40); entry->doc = entry->schema->doc; xmldoc_add_ref(entry->doc); } else { FIXME("failed to parse doc\n"); xmlFreeDoc(new_doc); heap_free(entry); entry = NULL; } xmlSchemaFreeParserCtxt(spctx); return entry; }
static cache_entry* cache_entry_from_xsd_doc(xmlDocPtr doc, xmlChar const* nsURI, MSXML_VERSION v) { cache_entry* entry = heap_alloc(sizeof(cache_entry)); xmlSchemaParserCtxtPtr spctx; xmlDocPtr new_doc = xmlCopyDoc(doc, 1); link_datatypes(new_doc); /* TODO: if the nsURI is different from the default xmlns or targetNamespace, * do we need to do something special here? */ entry->type = CacheEntryType_XSD; entry->ref = 0; spctx = xmlSchemaNewDocParserCtxt(new_doc); if ((entry->schema = Schema_parse(spctx))) { xmldoc_init(entry->schema->doc, v); entry->doc = entry->schema->doc; xmldoc_add_ref(entry->doc); } else { FIXME("failed to parse doc\n"); xmlFreeDoc(new_doc); heap_free(entry); entry = NULL; } xmlSchemaFreeParserCtxt(spctx); return entry; }
static cache_entry* cache_entry_from_xdr_doc(xmlDocPtr doc, xmlChar const* nsURI, MSXML_VERSION version) { cache_entry* entry = heap_alloc(sizeof(cache_entry)); xmlSchemaParserCtxtPtr spctx; xmlDocPtr new_doc = xmlCopyDoc(doc, 1), xsd_doc = XDR_to_XSD_doc(doc, nsURI); link_datatypes(xsd_doc); entry->type = CacheEntryType_XDR; entry->ref = 0; spctx = xmlSchemaNewDocParserCtxt(xsd_doc); if ((entry->schema = Schema_parse(spctx))) { entry->doc = new_doc; xmldoc_init(entry->schema->doc, version); xmldoc_init(entry->doc, version); xmldoc_add_ref(entry->doc); xmldoc_add_ref(entry->schema->doc); } else { FIXME("failed to parse doc\n"); xmlFreeDoc(new_doc); xmlFreeDoc(xsd_doc); heap_free(entry); entry = NULL; } xmlSchemaFreeParserCtxt(spctx); return entry; }
bool TasksetWriter::isValid(const xmlDocPtr doc) const { xmlDocPtr schema_doc = xmlReadFile(this->_schemafilename.c_str(), NULL, XML_PARSE_PEDANTIC); if (schema_doc == NULL) { // the schema cannot be loaded or is not well-formed return -1; } xmlSchemaParserCtxtPtr parser_ctxt = xmlSchemaNewDocParserCtxt(schema_doc); if (parser_ctxt == NULL) { // unable to create a parser context for the schema xmlFreeDoc(schema_doc); return -2; } xmlSchemaPtr schema = xmlSchemaParse(parser_ctxt); if (schema == NULL) { // the schema itself is not valid xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(schema_doc); return -3; } xmlSchemaValidCtxtPtr valid_ctxt = xmlSchemaNewValidCtxt(schema); if (valid_ctxt == NULL) { // unable to create a validation context for the schema xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(schema_doc); return -4; } int is_valid = (xmlSchemaValidateDoc(valid_ctxt, doc) == 0); xmlSchemaFreeValidCtxt(valid_ctxt); xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(schema_doc); // force the return value to be non-negative on success return is_valid ? 1 : 0; }
//this schema validation code is taken from http://wiki.njh.eu/XML-Schema_validation_with_libxml2 this code int Parser::validateAgainstSchema(const xmlDocPtr &_doc,const xmlDocPtr &_schema ) { xmlSchemaParserCtxtPtr parser_ctxt = xmlSchemaNewDocParserCtxt(_schema); if (parser_ctxt == NULL) { /* unable to create a parser context for the schema */ xmlFreeDoc(_schema); return -1; } xmlSchemaPtr schema = xmlSchemaParse(parser_ctxt); if (schema == NULL) { /* the schema itself is not valid */ xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(_schema); return -2; } xmlSchemaValidCtxtPtr valid_ctxt = xmlSchemaNewValidCtxt(schema); if (valid_ctxt == NULL) { /* unable to create a validation context for the schema */ xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(_schema); return -3; } int is_valid = (xmlSchemaValidateDoc(valid_ctxt, _doc) == 0); xmlSchemaFreeValidCtxt(valid_ctxt); xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); /* force the return value to be non-negative on success */ return is_valid ? 1 : 0; }
bool xml_validate(bool *pvalid, xmlDocPtr doc, const char *schema_path) { bool result = false; xmlDocPtr schema_doc = NULL; xmlSchemaParserCtxtPtr schema_parser_ctxt = NULL; xmlSchemaPtr schema = NULL; xmlSchemaValidCtxtPtr schema_valid_ctxt = NULL; int valid_rc; schema_doc = xmlReadFile(schema_path, NULL, XML_PARSE_NONET); if (schema_doc == NULL) goto cleanup; schema_parser_ctxt = xmlSchemaNewDocParserCtxt(schema_doc); if (schema_parser_ctxt == NULL) goto cleanup; schema = xmlSchemaParse(schema_parser_ctxt); if (schema == NULL) goto cleanup; schema_valid_ctxt = xmlSchemaNewValidCtxt(schema); if (schema_valid_ctxt == NULL) goto cleanup; valid_rc = xmlSchemaValidateDoc(schema_valid_ctxt, doc); if (valid_rc < 0) goto cleanup; if (pvalid != NULL) *pvalid = (valid_rc == 0); result = true; cleanup: xmlSchemaFreeValidCtxt(schema_valid_ctxt); xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(schema_parser_ctxt); if (schema_doc != NULL) xmlFreeDoc(schema_doc); return result; }
ReturnCode validateSchema(const TixiDocumentHandle handle, xmlDocPtr* schema_doc) { TixiDocument* document = getDocument(handle); xmlSchemaParserCtxtPtr parser_ctxt; xmlSchemaPtr schema; xmlSchemaValidCtxtPtr valid_ctxt; int is_valid; if (*schema_doc == NULL) { /* the schema cannot be loaded or is not well-formed */ return OPEN_SCHEMA_FAILED; } parser_ctxt = xmlSchemaNewDocParserCtxt(*schema_doc); if (parser_ctxt == NULL) { printMsg(MESSAGETYPE_ERROR, "Error: validateSchema: unable to create a parser context for the schema.\n"); xmlFreeDoc(*schema_doc); return FAILED; } schema = xmlSchemaParse(parser_ctxt); if (schema == NULL) { printMsg(MESSAGETYPE_ERROR, "Error: validateSchema: the schema itself is not valid.\n"); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(*schema_doc); return FAILED; } valid_ctxt = xmlSchemaNewValidCtxt(schema); if (valid_ctxt == NULL) { printMsg(MESSAGETYPE_ERROR, "Error: validateSchema: unable to create a validation context for the schema.\n"); xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(*schema_doc); return FAILED; } is_valid = (xmlSchemaValidateDoc(valid_ctxt, document->docPtr) == 0); xmlSchemaFreeValidCtxt(valid_ctxt); xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(*schema_doc); if (is_valid) { return SUCCESS; } else { return NOT_SCHEMA_COMPLIANT; } }
/* * call-seq: * from_document(doc) * * Create a new Schema from the Nokogiri::XML::Document +doc+ */ static VALUE from_document(VALUE klass, VALUE document) { xmlDocPtr doc; Data_Get_Struct(document, xmlDoc, doc); // In case someone passes us a node. ugh. doc = doc->doc; xmlSchemaParserCtxtPtr ctx = xmlSchemaNewDocParserCtxt(doc); VALUE errors = rb_ary_new(); xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher); #ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS xmlSchemaSetParserStructuredErrors( ctx, Nokogiri_error_array_pusher, (void *)errors ); #endif xmlSchemaPtr schema = xmlSchemaParse(ctx); xmlSetStructuredErrorFunc(NULL, NULL); xmlSchemaFreeParserCtxt(ctx); if(NULL == schema) { xmlErrorPtr error = xmlGetLastError(); if(error) Nokogiri_error_raise(NULL, error); else rb_raise(rb_eRuntimeError, "Could not parse document"); return Qnil; } VALUE rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema); rb_iv_set(rb_schema, "@errors", errors); return rb_schema; return Qnil; }
int xml2lpc_validate(xml2lpc_context *xmlCtx) { xmlSchemaValidCtxtPtr validCtx; xmlSchemaParserCtxtPtr parserCtx; int ret; xml2lpc_context_clear_logs(xmlCtx); parserCtx = xmlSchemaNewDocParserCtxt(xmlCtx->xsd); validCtx = xmlSchemaNewValidCtxt(xmlSchemaParse(parserCtx)); xmlSchemaSetValidErrors(validCtx, xml2lpc_genericxml_error, xml2lpc_genericxml_warning, xmlCtx); ret = xmlSchemaValidateDoc(validCtx, xmlCtx->doc); if(ret > 0) { if(strlen(xmlCtx->warningBuffer) > 0) xml2lpc_log(xmlCtx, XML2LPC_WARNING, "%s", xmlCtx->warningBuffer); if(strlen(xmlCtx->errorBuffer) > 0) xml2lpc_log(xmlCtx, XML2LPC_ERROR, "%s", xmlCtx->errorBuffer); } else if(ret < 0) { xml2lpc_log(xmlCtx, XML2LPC_ERROR, "Internal error"); } xmlSchemaFreeValidCtxt(validCtx); return ret; }
/* This code is from http://wiki.njh.eu/XML-Schema_validation_with_libxml2 */ static int is_valid(const xmlDocPtr doc, const char *schema_filename) { xmlDocPtr schema_doc = xmlReadFile(schema_filename, NULL, XML_PARSE_NONET); if (schema_doc == NULL) { /* the schema cannot be loaded or is not well-formed */ fprintf(stderr, "Error: Unable to load the schema file \"%s\"\n", schema_filename); exit(1); } xmlSchemaParserCtxtPtr parser_ctxt = xmlSchemaNewDocParserCtxt( schema_doc); if (parser_ctxt == NULL) { /* unable to create a parser context for the schema */ xmlFreeDoc(schema_doc); return -2; } xmlSchemaPtr schema = xmlSchemaParse(parser_ctxt); if (schema == NULL) { /* the schema itself is not valid */ xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(schema_doc); return -3; } xmlSchemaValidCtxtPtr valid_ctxt = xmlSchemaNewValidCtxt(schema); if (valid_ctxt == NULL) { /* unable to create a validation context for the schema */ xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(schema_doc); return -4; } int is_valid = (xmlSchemaValidateDoc(valid_ctxt, doc) == 0); xmlSchemaFreeValidCtxt(valid_ctxt); xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(schema_doc); /* force the return value to be non-negative on success */ return is_valid ? 1 : 0; }
bool XMLSchema::validate(xmlDocPtr doc, const std::string& xsd) { xmlParserOption parserOption(XML_PARSE_NONET); xmlDocPtr schemaDoc = xmlReadMemory(xsd.c_str(), xsd.size(), NULL, NULL, parserOption); xmlSchemaParserCtxtPtr parserCtxt = xmlSchemaNewDocParserCtxt(schemaDoc); xmlSchemaSetParserStructuredErrors(parserCtxt, &OCISchemaParserStructuredErrorHandler, m_global_context); xmlSchemaPtr schema = xmlSchemaParse(parserCtxt); xmlSchemaValidCtxtPtr validCtxt = xmlSchemaNewValidCtxt(schema); xmlSchemaSetValidErrors(validCtxt, &OCISchemaValidityError, &OCISchemaValidityDebug, m_global_context); bool valid = (xmlSchemaValidateDoc(validCtxt, doc) == 0); xmlFreeDoc(schemaDoc); xmlSchemaFreeParserCtxt(parserCtxt); xmlSchemaFree(schema); xmlSchemaFreeValidCtxt(validCtxt); return valid; }
static xmlDocPtr parse_arguments(const char *data, gsize len, GError **err) { xmlDocPtr schema_doc = NULL; xmlSchemaParserCtxtPtr schema_parser = NULL; xmlSchemaPtr schema = NULL; xmlSchemaValidCtxtPtr validator = NULL; xmlDocPtr doc = NULL; xmlDocPtr ret = NULL; /* Read schema */ schema_doc = xmlReadFile(VMNETFS_SCHEMA_PATH, NULL, 0); if (schema_doc == NULL) { g_set_error(err, VMNETFS_CONFIG_ERROR, VMNETFS_CONFIG_ERROR_INVALID_SCHEMA, "Couldn't parse XML schema document"); goto out; } /* Load schema */ schema_parser = xmlSchemaNewDocParserCtxt(schema_doc); g_assert(schema_parser); schema = xmlSchemaParse(schema_parser); if (schema == NULL) { g_set_error(err, VMNETFS_CONFIG_ERROR, VMNETFS_CONFIG_ERROR_INVALID_SCHEMA, "Couldn't parse XML schema"); goto out; } validator = xmlSchemaNewValidCtxt(schema); g_assert(validator); /* Parse XML document */ doc = xmlReadMemory(data, len, NULL, NULL, 0); if (doc == NULL) { g_set_error(err, VMNETFS_CONFIG_ERROR, VMNETFS_CONFIG_ERROR_INVALID_CONFIG, "Couldn't parse XML document"); goto out; } /* Validate XML document */ if (xmlSchemaValidateDoc(validator, doc)) { g_set_error(err, VMNETFS_CONFIG_ERROR, VMNETFS_CONFIG_ERROR_INVALID_CONFIG, "Config XML did not validate"); goto out; } ret = doc; doc = NULL; out: if (doc) { xmlFreeDoc(doc); } if (validator) { xmlSchemaFreeValidCtxt(validator); } if (schema) { xmlSchemaFree(schema); } if (schema_parser) { xmlSchemaFreeParserCtxt(schema_parser); } if (schema_doc) { xmlFreeDoc(schema_doc); } return ret; }
// check the xml validity int is_valid(char *filename,char *schema_filename) { // Init libxml xmlInitParser(); LIBXML_TEST_VERSION assert(filename); // Load XML document doc = xmlParseFile(filename); if (doc == NULL) { fprintf(stderr, "ERROR: unable to parse file \"%s\"\n", filename); return(-1); } // Create xpath evaluation context xpathCtx = xmlXPathNewContext(doc); if(xpathCtx == NULL) { printf("ERROR: unable to create new XPath context\n"); xmlFreeDoc(doc); return(-1); } // Load the schema xmlDocPtr schema_doc = xmlReadFile(schema_filename, NULL, XML_PARSE_NONET); if (schema_doc == NULL) { // the schema cannot be loaded or is not well-formed printf("ERROR: the schema cannot be loaded or is not well-formed\n"); return -1; } // Create the XML parser xmlSchemaParserCtxtPtr parser_ctxt = xmlSchemaNewDocParserCtxt(schema_doc); if (parser_ctxt == NULL) { // unable to create a parser context for the schema printf("ERROR: unable to create a parser context for the schema\n"); xmlFreeDoc(schema_doc); return -1; } // Validate the schema xmlSchemaPtr schema = xmlSchemaParse(parser_ctxt); if (schema == NULL) { // the schema itself is not valid printf("ERROR: the schema itself is not valid\n"); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(schema_doc); return -1; } // Validate the schema file xmlSchemaValidCtxtPtr valid_ctxt = xmlSchemaNewValidCtxt(schema); if (valid_ctxt == NULL) { // Unable to create a validation context for the schema printf("ERROR: unable to create a validation context for the schema\n"); xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(schema_doc); return -1; } // Validate the file if (xmlSchemaValidateDoc(valid_ctxt, doc) != 0){ // Returns 0 if the document is schemas valid, printf("ERROR: Schema file not valid\n"); // a positive error code number otherwise and -1 in case of internal or API error. return -1; } xmlSchemaFreeValidCtxt(valid_ctxt); xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(schema_doc); return 0; }
/** * \fn msiXmlDocSchemaValidate(msParam_t *xmlObj, msParam_t *xsdObj, msParam_t *status, ruleExecInfo_t *rei) * * \brief This microservice validates an XML file against an XSD schema, both iRODS objects. * * \module xml * * \since pre-2.1 * * \author Antoine de Torcy * \date 2008/05/29 * * \usage See clients/icommands/test/rules3.0/ * * \param[in] xmlObj - a msParam of type DataObjInp_MS_T or STR_MS_T which is irods path of the XML object. * \param[in] xsdObj - a msParam of type DataObjInp_MS_T or STR_MS_T which is irods path of the XSD object. * \param[out] status - a msParam of type INT_MS_T which is a validation result. * \param[in,out] rei - The RuleExecInfo structure that is automatically * handled by the rule engine. The user does not include rei as a * parameter in the rule invocation. * * \DolVarDependence None * \DolVarModified None * \iCatAttrDependence None * \iCatAttrModified None * \sideeffect None * * \return integer * \retval 0 on success * \pre None * \post None * \sa None **/ int msiXmlDocSchemaValidate(msParam_t *xmlObj, msParam_t *xsdObj, msParam_t *status, ruleExecInfo_t *rei) { /* for parsing msParams and to open iRODS objects */ dataObjInp_t xmlObjInp, *myXmlObjInp; dataObjInp_t xsdObjInp, *myXsdObjInp; int xmlObjID, xsdObjID; /* for getting size of objects to read from */ rodsObjStat_t *rodsObjStatOut = NULL; /* for reading from iRODS objects */ openedDataObjInp_t openedDataObjInp; bytesBuf_t *xmlBuf = NULL; char *tail; /* for xml parsing and validating */ xmlDocPtr doc, xsd_doc; xmlSchemaParserCtxtPtr parser_ctxt; xmlSchemaPtr schema; xmlSchemaValidCtxtPtr valid_ctxt; bytesBuf_t *errBuf; /* misc. to avoid repeating rei->rsComm */ rsComm_t *rsComm; /************************************* USUAL INIT PROCEDURE **********************************/ /* For testing mode when used with irule --test */ RE_TEST_MACRO (" Calling msiXmlDocSchemaValidate") /* Sanity checks */ if (rei == NULL || rei->rsComm == NULL) { rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: input rei or rsComm is NULL."); return (SYS_INTERNAL_NULL_INPUT_ERR); } rsComm = rei->rsComm; /************************************ ADDITIONAL INIT SETTINGS *********************************/ /* XML constants */ xmlSubstituteEntitiesDefault(1); xmlLoadExtDtdDefaultValue = 1; /* allocate memory for output error buffer */ errBuf = (bytesBuf_t *)malloc(sizeof(bytesBuf_t)); errBuf->buf = strdup(""); errBuf->len = strlen((char*)errBuf->buf); /* Default status is failure, overwrite if success */ fillBufLenInMsParam (status, -1, NULL); /********************************** RETRIEVE INPUT PARAMS **************************************/ /* Get path of XML document */ rei->status = parseMspForDataObjInp (xmlObj, &xmlObjInp, &myXmlObjInp, 0); if (rei->status < 0) { rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: input xmlObj error. status = %d", rei->status); free(errBuf); return (rei->status); } /* Get path of schema */ rei->status = parseMspForDataObjInp (xsdObj, &xsdObjInp, &myXsdObjInp, 0); if (rei->status < 0) { rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: input xsdObj error. status = %d", rei->status); free(errBuf); return (rei->status); } /******************************** OPEN AND READ FROM XML OBJECT ********************************/ /* Open XML file */ if ((xmlObjID = rsDataObjOpen(rsComm, &xmlObjInp)) < 0) { rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Cannot open XML data object. status = %d", xmlObjID); free(errBuf); return (xmlObjID); } /* Get size of XML file */ rei->status = rsObjStat (rsComm, &xmlObjInp, &rodsObjStatOut); if (rei->status < 0 || !rodsObjStatOut) { rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Cannot stat XML data object. status = %d", rei->status); free(errBuf); return (rei->status); } /* xmlBuf init */ /* memory for xmlBuf->buf is allocated in rsFileRead() */ xmlBuf = (bytesBuf_t *) malloc (sizeof (bytesBuf_t)); memset (xmlBuf, 0, sizeof (bytesBuf_t)); /* Read content of XML file */ memset (&openedDataObjInp, 0, sizeof (openedDataObjInp_t)); openedDataObjInp.l1descInx = xmlObjID; openedDataObjInp.len = (int)rodsObjStatOut->objSize + 1; /* extra byte to add a null char */ rei->status = rsDataObjRead (rsComm, &openedDataObjInp, xmlBuf); /* add terminating null character */ tail = (char*)xmlBuf->buf; tail[openedDataObjInp.len - 1] = '\0'; /* Close XML file */ rei->status = rsDataObjClose (rsComm, &openedDataObjInp); /* cleanup */ freeRodsObjStat (rodsObjStatOut); /*************************************** PARSE XML DOCUMENT **************************************/ /* Parse xmlBuf.buf into an xmlDocPtr */ doc = xmlParseDoc((xmlChar*)xmlBuf->buf); clearBBuf(xmlBuf); if (doc == NULL) { rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: XML document cannot be loaded or is not well-formed."); free(errBuf); xmlCleanupParser(); return (USER_INPUT_FORMAT_ERR); } /******************************** OPEN AND READ FROM XSD OBJECT ********************************/ /* Open schema file */ if ((xsdObjID = rsDataObjOpen(rsComm, &xsdObjInp)) < 0) { rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Cannot open XSD data object. status = %d", xsdObjID); free(errBuf); xmlFreeDoc(doc); xmlCleanupParser(); return (xsdObjID); } /* Get size of schema file */ rei->status = rsObjStat (rsComm, &xsdObjInp, &rodsObjStatOut); /* Read entire schema file */ memset (&openedDataObjInp, 0, sizeof (openedDataObjInp_t)); openedDataObjInp.l1descInx = xsdObjID; openedDataObjInp.len = (int)rodsObjStatOut->objSize + 1; /* to add null char */ rei->status = rsDataObjRead (rsComm, &openedDataObjInp, xmlBuf); /* add terminating null character */ tail = (char*)xmlBuf->buf; tail[openedDataObjInp.len - 1] = '\0'; /* Close schema file */ rei->status = rsDataObjClose (rsComm, &openedDataObjInp); /* cleanup */ freeRodsObjStat (rodsObjStatOut); /*************************************** PARSE XSD DOCUMENT **************************************/ /* Parse xmlBuf.buf into an xmlDocPtr */ xsd_doc = xmlParseDoc((xmlChar*)xmlBuf->buf); clearBBuf(xmlBuf); if (xsd_doc == NULL) { rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: XML Schema cannot be loaded or is not well-formed."); free(errBuf); xmlFreeDoc(doc); xmlCleanupParser(); return (USER_INPUT_FORMAT_ERR); } /**************************************** VALIDATE DOCUMENT **************************************/ /* Create a parser context */ parser_ctxt = xmlSchemaNewDocParserCtxt(xsd_doc); if (parser_ctxt == NULL) { rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Unable to create a parser context for the schema."); free(errBuf); xmlFreeDoc(xsd_doc); xmlFreeDoc(doc); xmlCleanupParser(); return (USER_INPUT_FORMAT_ERR); } /* Parse the XML schema */ schema = xmlSchemaParse(parser_ctxt); if (schema == NULL) { rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Invalid schema."); free(errBuf); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(doc); xmlFreeDoc(xsd_doc); xmlCleanupParser(); return (USER_INPUT_FORMAT_ERR); } /* Create a validation context */ valid_ctxt = xmlSchemaNewValidCtxt(schema); if (valid_ctxt == NULL) { rodsLog (LOG_ERROR, "msiXmlDocSchemaValidate: Unable to create a validation context for the schema."); free(errBuf); xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(xsd_doc); xmlFreeDoc(doc); xmlCleanupParser(); return (USER_INPUT_FORMAT_ERR); } /* Set myErrorCallback() as the default handler for error messages and warnings */ xmlSchemaSetValidErrors(valid_ctxt, (xmlSchemaValidityErrorFunc)myErrorCallback, (xmlSchemaValidityWarningFunc)myErrorCallback, errBuf); /* Validate XML doc */ rei->status = xmlSchemaValidateDoc(valid_ctxt, doc); /******************************************* WE'RE DONE ******************************************/ /* return both error code and messages through status */ resetMsParam (status); fillBufLenInMsParam (status, rei->status, errBuf); /* cleanup of all xml parsing stuff */ xmlSchemaFreeValidCtxt(valid_ctxt); xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parser_ctxt); xmlFreeDoc(doc); xmlFreeDoc(xsd_doc); xmlCleanupParser(); return (rei->status); }