users@jaxb.java.net

Re: Unsymmetrical validation

From: Ryan Shoemaker - JavaSoft East <Ryan.Shoemaker_at_Sun.COM>
Date: Mon, 23 Feb 2004 10:32:58 -0500

Adrian Brogan wrote:

>
> Given the following as a fragment of a schema we use,
>
> <xsd:element name="PARTYCODE">
> <xsd:complexType mixed="false">
> <xsd:sequence>
> <xsd:element ref="IDDESC" minOccurs="0" maxOccurs="1"/>
> <xsd:element ref="IDCODE" minOccurs="1" maxOccurs="1"/>
> </xsd:sequence>
> <xsd:attribute name="IDTYPE" type="xsd:string" use="required"/>
> </xsd:complexType>
> </xsd:element>
>
> when we parse an XML file based on the schema containing the above
> fragment, and given the data for this fragment is
>
> <PARTYCODE IDTYPE=”a”>
> <IDDESC>b</IDDESC>
> <IDTYPE></IDTYPE>
> </PARTYCODE>
>
> the unmarshall method reads in the data to the JAXB model without a
> problem (even though the IDCODE element is empty).
>

If you are unmarshalling with validation enabled, then it is a bug.
(In which case, please file a new defect on java.net including a small
test case that reproduces the problem).

How is <IDCODE> defined in the schema?

>
>
> However, when we recreate the XML document (after building up the JAXB
> model from the same data), the marshal method reports the mandatory
> element IDCODE missing.
>
>
>
> Is this how is should behave?
>

The JAXB spec is very vague on how JAXB providers are supposed to
handle invalid content. It clearly says that valid xml data must
marshal and unmarshal, but it leaves the door wide open on how to
handle invalid data. Generally speaking, the Sun RI is very strict
about invalid xml - especially missing elements.

Thanks,

--Ryan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net