<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 outputelement 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 instancexmlDebugDumpDocument() producesDOCUMENTversion=1.0standalone=trueELEMENT zoo:cageRequestnamespace zoo href=http://www.example.org/Zoonamespace xsi href=http://www.w3.org/2001/XMLSchema-instanc...ELEMENT animalATTRIBUTE xsi:typeTEXTcontent=zoo:FishELEMENT nameTEXTcontent=Blue Fin TunaELEMENT numberOfFinsTEXTcontent=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 validCtxtxmlSchemaFreeParserCtxt(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 advanceAndy