Re: OT Re: [xml] XSD validation example needed



Hi,

Samuel Díaz García wrote:
Well, I validate an XML document (in my app) in two steps:
  1) With the XML internal XSD.
  2) With a local XSD.

¿any help with the first step as I want?
[...]

In case the information that the validation context needs to
be created with a NULL value for the @schema argument was not
explitic enough, you may try the following function sketch to
validate as you want in 1). It will gather the XML Schema documents
specified by the xsi information and validate against them.

{
 int res;
 xmlDocPtr doc;
 xmlSchemaValidCtxtPtr xsdCtxt;

 /*
 * Load the document.
 */
 doc = xmlReadFile(BAD_CAST "foo.xml", NULL, 0);
 if (doc == NULL)
   return (-1);

 /*
 * Create the validation context with NULL as the
 * @schema argument.
 */
 xsdCtxt = xmlSchemaNewValidCtxt(NULL);
 if (xsdCtxt == NULL) {
   xmlFreeDoc(doc);
   return (-1);
 }

 /*
 * Validate the document.
 */
 res = xmlSchemaValidateDoc(xsdCtxt, doc);

 xmlSchemaFreeValidCtxt(xsdCtxt);
 xmlFreeDoc(doc);

 return (res);
}


Cheers,

Kasimier



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