W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2011

Fwd: libxml2 does xmlSchemaValidateDoc() support xml schema extensions?

From: Andy Davidson <andy_davidson@apple.com>
Date: Mon, 12 Dec 2011 18:12:48 -0800
To: xmlschema-dev@w3.org
Message-id: <03454E0B-3D71-495D-959A-EAF3D968A61B@apple.com>
Does anyone know if libxml2 supports  http://www.w3.org/TR/xmlschema-0/#DerivExt   ?

thanks in advance

Andy

Begin forwarded message:

> From: Andy Davidson <andy_davidson@apple.com>
> Date: December 12, 2011 6:10:14 PM PST
> To: xml@gnome.org
> Subject: libxml2 does xmlSchemaValidateDoc() support xml schema extensions?
> 
> 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
> 
> 
> 
> 
>     <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=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
> (gdb) 
> 
> 
> Do I need to tweak my validation code ? 
> 
> 
> (this is an ObjC listing)
> 
>     
>     
>     const char *schemaFileNameStr = [xmlSchemaFilePath cStringUsingEncoding: NSASCIIStringEncoding];
>     
>     // http://www.xmlsoft.org/html/libxml-parser.html#xmlReadFile
>     // 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;
>     }
>     
>     // http://www.xmlsoft.org/html/libxml-xmlschemas.html#xmlSchemaNewDocParserCtxt
>     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;
>     }
>     
>     // http://www.xmlsoft.org/html/libxml-xmlschemas.html#xmlSchemaParse
>     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;
>     }
>     
>     // http://www.xmlsoft.org/html/libxml-xmlschemas.html#xmlSchemaNewValidCtxt
>     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);
>     
>     // http://www.xmlsoft.org/html/libxml-xmlschemas.html#xmlSchemaValidateDoc
>     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
> 
Received on Tuesday, 13 December 2011 02:13:18 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:19 UTC