users@jaxb.java.net

Re: <xsd:extension> causes validation error

From: Pete Hendry <peter.hendry_at_capeclear.com>
Date: Fri, 06 Jun 2003 08:37:32 +1200

The problem is that there is no xsi:type information on the matrix
element. When using polymorphism in this way in schema the xsi:type
attribute is required to tell the parser that the type of the element is
not the type it will find in the schema definition. Without it the
parser (schema parser as well as JAXB) will try to validate the element
against whatever type it finds for it in the schema.

Pete

Filip Rindler wrote:

>Hi!
>
>I'm having another problem with the <xsd:extension> feature of XML schema:
>
>Here's an excerpt from my schema again:
>
><xsd:complexType name="Matrix">
> <xsd:attribute name="className" type="xsd:string" />
></xsd:complexType>
>
><xsd:complexType name="Matrix2DGrid">
> <xsd:complexContent>
> <xsd:extension base="Matrix">
> <xsd:all>
> <xsd:element name="size" type="Matrix2DGridDimension" />
> <xsd:element name="neighborhoodRelation" type="xsd:int" />
> <xsd:element name="cells" type="CellsList" />
> </xsd:all>
> </xsd:extension>
> </xsd:complexContent>
></xsd:complexType>
>
>And here's an XML file that was generated (and validated) using
>JAXB-generated classes:
>
><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
><ns1:mtxfile
>xsi:schemaLocation="http://www.filip-rindler.de/cytorit/xml/mtxfile
>http://www.filip-rindler.de/cytorit/xml/mtxfile.xsd"
>xsi:noNamespaceSchemaLocation="http://www.filip-rindler.de/cytorit/xml/mtxfi
>le http://www.filip-rindler.de/cytorit/xml/mtxfile.xsd"
>xmlns:ns1="http://www.filip-rindler.de/cytorit/xml"
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
><ns1:minVersion>100</ns1:minVersion>
><ns1:matrix className="de.filiprindler.cytorit.standard.Matrix2DGrid">
><--- HERE
><ns1:size>
><ns1:origin>
><ns1:x>1</ns1:x>
><ns1:y>1</ns1:y>
></ns1:origin>
><ns1:width>10</ns1:width>
><ns1:height>10</ns1:height>
></ns1:size>
><ns1:neighborhoodRelation>1</ns1:neighborhoodRelation>
><ns1:cells></ns1:cells>
></ns1:matrix>
><ns1:parameters></ns1:parameters>
></ns1:mtxfile>
>
>However, when reading the document I get a
>[com.sun.msv.verifier.ValidityViolation: unexpected attribute "className"]
>exception!
>How is this possible that I can successfully validate and save the file but
>when reding it, i get this exception?
>I think it has something to do with the fact that the className attribute
>has been derived from the Matrix complexType to the Matrix2DGrid subtype.
>
>Thanks!
>
>Filip Rindler
>
>
>