users@jaxb.java.net

Re: <xsd:extension> causes validation error

From: Filip Rindler <filip.rindler_at_gmx.de>
Date: Fri, 06 Jun 2003 14:18:43 +0200

Hi!

I'm sorry, but I don't see the problem. To me as a Java programmer, it seems
that if i use the <xsd:extension> tag, it will take all the properties from
the supertype and put them in the subtype. And this is exactly what JAXB is
doing - it generates setClassName() for XMLBMatrix2DGrid (JAXB-generated
class for Matrix2DGrid complex type) as well. This also is in the schema:

<xsd:element name="mtxfile" type="MTXFile">
</xsd:element>

<xsd:complexType name="MTXFile">
 <xsd:all>
  <xsd:element name="minVersion" type="xsd:int" />
  <xsd:element name="matrix" type="Matrix2DGrid" /> <---
there is a type (?)
  <xsd:element name="parameters" type="PropertyTable" />
 </xsd:all>
</xsd:complexType>

I'm not too experienced with XML so maybe you could do me the favor of
telling me what to change...

Thanks in advance!

Filip Rindler


> 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/mtxf
i
> >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
> >
> >
> >
>