users@jaxb.java.net

Re: Unmarshal fails for imported namespace

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 18 Aug 2005 17:07:52 -0700

Try unmarshaller.setValidating(true).

This typically gives you better error message of what the unmarshaller
is really expecting.

arun.shankar_at_accenture.com wrote:
> Hello,
>
> I have a schema file ElemA.xsd that imports a namespace. When I try to unmarshal a sample XML file, the the Unmarshaler gives an "Unexpected element" error when it encounters an element within the imported file.
>
> DefaultValidationEventHandler: [ERROR]: Unexpected element {my/nmspc/b}:theElemC
>
> Can JAXB work with imported namespaces? If it can, what am I doing wrong? Thanks.
>
> I am using xjc version "1.0.5-b16-fcs" and I invoke xjc.bat as xjc.bat -d ../sources -p debug.jaxb -readOnly ElemA.xsd
>
> Here are the schemas:
>
> ElemA.xsd
>
> <xs:schema
> targetNamespace="my/nmspc/a"
> xmlns:b="my/nmspc/b"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified"
> attributeFormDefault="unqualified" version="1">
>
> <xs:import namespace="my/nmspc/b" schemaLocation="ElemB.xsd"/>
> <xs:element name="ElemA">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="theElemB">
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="b:ElemB"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
>
> -------------------------------------------------------------
>
> ElemB.xsd , which is imported by ElemA
>
> <xs:schema targetNamespace="my/nmspc/b" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:c="my/nmspc/b" version="1">
> <!-- xs:include schemaLocation="ElemC.xsd"/ -->
> <xs:element name="ElemB">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="theElemC">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="ElemC">
> <xs:complexType>
> <xs:attribute name="attrForC" use="required">
> <xs:simpleType>
> <xs:restriction base="xs:string">
> <xs:maxLength value="100"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:attribute>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> <xs:attribute name="someAttr" use="required">
> <xs:simpleType>
> <xs:restriction base="xs:string">
> <xs:maxLength value="10"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:attribute>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
> -------------------------------------------------------------
>
> The sample XML
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <ElemA xmlns="my/nmspc/a" xmlns:b="my/nmspc/b"
>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="my/nmspc/a D:\JaxbDebug\etc\ElemA.xsd">
> <theElemB>
> <b:ElemB someAttr="String">
> <b:theElemC>
> <b:ElemC attrForC="String"/>
> </b:theElemC>
> </b:ElemB>
> </theElemB>
> </ElemA>
>
> -------------------------------------------------------------
>
> Regards,
> Arun Shankar
>
>
>
> This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com