[xml] Validation of XML documents against schema



Hi,
 
I am a newbie to libxml2 and most Visual C++ concepts. I do have a strong background in OOP from Java and .NET. My problem is that I am creating a small VC++ 6.0 application that "simply" validates an XML document against a supplied schema.
 
My code is shown below, which is similar to Eric Haszlakiewicz's post http://mail.gnome.org/archives/xml/2004-April/msg00257.html
 
My XML document is edited using XML Shell and I've successfully validated it using that software. I have deliberately changed one of the values so that it doesn't validate but my program doesn't seem to produce the error (including line number and everything) that I want. Could someone tell me how to use xmlSetStructuredErrorFunc and xmlStruturedErrorFunc in order to get my program to work? I really need the specifics. Thankyou very much. My code is below:
 
void xerror(void *ctxt, const char *fmt, ...)
{
 va_list args;
 //int ret;
 //int curlen;
 va_start(args, fmt);
 
 //curlen = strlen((char *)data);
 //if (curlen >= 2048)
 // return 0;
 //ret =
 vprintf(fmt, args);
 va_end(args);
 //return ret;
}
BOOL processValidate::doValidation(CString fileName)
{
 xmlSchemaPtr schema;
 xmlSchemaParserCtxtPtr ctxt;
 
 xmlDocPtr doc;
 
 int oline = xmlLineNumbersDefault(1);
 ctxt = xmlSchemaNewParserCtxt(SCHEMA_FILE);
 schema = xmlSchemaParse(ctxt);
 doc = xmlParseFile(fileName);
 if (doc == NULL)
 {
  return 0;
 }
 else
 { 
  xmlSchemaValidCtxtPtr validCtxt;
  int ret;
  validCtxt = xmlSchemaNewValidCtxt(schema);
  
  xmlSchemaSetValidErrors(validCtxt,
       (xmlSchemaValidityErrorFunc) xerror,
       (xmlSchemaValidityWarningFunc) xerror,
       stderr);
  ret = xmlSchemaValidateDoc(validCtxt, doc);
  
  xmlSchemaFreeValidCtxt(validCtxt);
  xmlFreeDoc(doc);
  xmlSchemaFree(schema);
  xmlSchemaFreeParserCtxt(ctxt);
  xmlLineNumbersDefault(oline);
  if (ret == 0)
  {
   return 1;
  }
  else if (ret > 0)
  {  
   return 0;
  }
  else
  {  
   return 0; 
  }
     
 }
}
Regards,
 
Noah.


Looking to buy a new house? Try http://property.ninemsn.com.au/

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]