Hi I am using libxml2. I use xmlSchemaValidateDoc() to make sure my xml is valid. Recently we started using Extension to define new complexTypes. The description for extensions can be found at http://www.w3.org/TR/xmlschema-0/#DerivExt These instance do not validate using libxml2. I am able to validate these instance using java version "1.6.0_29" Attached is my test Zoo.xsd, and the instance I am trying to validate |
ZooRequest.xsd
Description: Binary data
<complexType name="Animal"> <sequence> <element name="name" type="string" /> </sequence> </complexType> <complexType name="Fish"> <complexContent> <extension base="zoo:Animal"> <sequence> <element name="numberOfFins" type="integer" /> </sequence> </extension> </complexContent> </complexType> My xml instance is <?xml version="1.0" encoding="UTF-8"?> <zoo:cageRequest xmlns:zoo="http://www.example.org/Zoo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <animal xsi:type="zoo:Fish"> <name>Blue Fin Tuna</name> <numberOfFins>4</numberOfFins> </animal> </zoo:cageRequest> xmlSchemaValidateDoc() generates the following output 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. the error returned is 1871 for instance xmlDebugDumpDocument() produces DOCUMENT version=1.0 standalone=true ELEMENT zoo:cageRequest namespace zoo href=""> namespace xsi href=""> ELEMENT animal ATTRIBUTE xsi:type TEXT content=zoo:Fish ELEMENT name TEXT content=Blue Fin Tuna ELEMENT numberOfFins TEXT content=4 (gdb) Do I need to tweak my validation code ? (this is an ObjC listing)
const char *schemaFileNameStr = [xmlSchemaFilePath cStringUsingEncoding: NSASCIIStringEncoding]; // second arg, null, is document encoding // XML_PARSE_NONET option means "Forbid network access" xmlDocPtr schemaDoc = xmlReadFile(schemaFileNameStr, NULL, XML_PARSE_NONET); NSString *errorMsgRoot = @"**** ERROR: POSXMLSchemaValidator.m createAndAddValidatorFor:, "; if (schemaDoc == NULL) { /* the schema cannot be loaded or is not well-formed */ NSLog(@"%@ the schema: %s can not be loaded or is not well-formed", errorMsgRoot, schemaFileNameStr); return ret; } xmlSchemaParserCtxtPtr parserCtxt = xmlSchemaNewDocParserCtxt(schemaDoc); if (parserCtxt == NULL) { /* unable to create a parser context for the schema */ xmlFreeDoc(schemaDoc); NSLog(@"%@ unable to create a parser context for schema %s", errorMsgRoot, schemaFileNameStr); return ret; } xmlSchemaPtr schema = xmlSchemaParse(parserCtxt); if (schema == NULL) { /* the schema itself is not valid */ xmlSchemaFreeParserCtxt(parserCtxt); xmlFreeDoc(schemaDoc); NSLog(@"%@ the schema %s is not valid", errorMsgRoot, schemaFileNameStr); return ret; } xmlSchemaValidCtxtPtr validCtxt = xmlSchemaNewValidCtxt(schema); if (validCtxt == NULL) { /* unable to create a validation context for the schema */ xmlSchemaFree(schema); xmlSchemaFreeParserCtxt(parserCtxt); xmlFreeDoc(schemaDoc); NSLog(@"%@ unable to validation context for schema %s", errorMsgRoot, schemaFileNameStr); return ret; }
//xmlSchemaFree(schema); causes crash when we try to use validCtxt xmlSchemaFreeParserCtxt(parserCtxt); xmlFreeDoc(schemaDoc); int error = xmlSchemaValidateDoc(validCtxt.validCtxt, doc); if (error == 0) { NSLog(@"document is a valid instance of %@", schemaFileName); ret = YES; } Is this a bug? thanks in advance Andy |
_______________________________________________ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org http://mail.gnome.org/mailman/listinfo/xml