p.s. Bellow is a long email I was going to send before I got the surprise I mentioned above. There is a nice code example of how how to validate. Its much simpler than the other examples I have seen posted in the past
On Dec 13, 2011, at 7:19 AM, Piotr Sipika wrote:
I wrote a sample program (in C) to attempt to mimic what you have, and
was able to successfully validate the instance against the schema you
provided.
Would you be willing to send my your sample C program?
I must be missing a function call somewhere? My XML/XSD files that do not use extensions validate so I think my basic code structure is correct. In your original post you mentioned "xmllint". I did not know about that tool. All of my files validate according to xmllint.I stepped through xmllint to see how it worked. Its very complicated. I must have missed something. Looking at the xmllint source I was able to simplify my code and get rid some some memory leaks.
Here is my simplified code listing based on the xmllint source
const char *schemaFileNameStr = ...;
xmlSchemaParserCtxtPtr ctxt = xmlSchemaNewParserCtxt(schemaFileNameStr);
xmlSchemaSetParserErrors(ctxt,
(xmlSchemaValidityErrorFunc) fprintf,
(xmlSchemaValidityWarningFunc) fprintf,
stderr);
xmlSchemaPtr wxschemas = xmlSchemaParse(ctxt);
if (wxschemas == NULL) {
NSLog(@"******* ERROR schema %@ failed to compile\n", xmlSchemaFilePath);
return ret;
}
xmlSchemaFreeParserCtxt(ctx);
for (all the xml files) {
xmlSchemaValidCtxtPtr vctxt = xmlSchemaNewValidCtxt(wxschemas);
xmlSchemaSetValidErrors(vctxt,
(xmlSchemaValidityErrorFunc) fprintf,
(xmlSchemaValidityWarningFunc) fprintf,
stderr);
int error = xmlSchemaValidateDoc(vctxt, doc);
if (error == 0) {
ret = YES;
} else if (error > 0) {
ret = NO;
fprintf(stderr, "%s fails to validate\n", filename);
} else {
ret = NO; // validation generated an internal error
}
xmlSchemaFreeValidCtxt(vctxt);
}
<?xml version="1.0" encoding="UTF-8"?>
<animal xsi:type="zoo:Fish">
<name>Blue Fin Tuna</name>
<numberOfFins>4</numberOfFins>
</animal>
</zoo:cageRequest>
element animal: Schemas validity error : Element 'animal', attribute 'xsi:type': The attribute 'xsi:type' is not allowed.
element numberOfFins: Schemas validity error : Element 'numberOfFins': This element is not expected.
DOCUMENT
version=1.0
standalone=true
ELEMENT zoo:cageRequest
namespace zoo href=http://www.example.org/Zoo
namespace xsi href=http://www.w3.org/2001/XMLSchema-instanc...
ELEMENT animal
ATTRIBUTE xsi:type
TEXT
content=zoo:Fish
ELEMENT name
TEXT
content=Blue Fin Tuna
ELEMENT numberOfFins
TEXT
content=4