users@jaxb.java.net

validation issue

From: Greg Thoenen <gthoenen_at_infopia.com>
Date: Thu, 10 Jan 2008 10:48:37 -0700

Hi,

I'm new to JAXB, so sorry if this is obvious....

I'm using JAXB 2.1.6 (downloaded separate, not as part of glassfish),
JDK 5, xerces 2.9.0, and xalan 2.7.1. I've run xjc to generate java
stubs from the attached schema. It generates a Product class (among
others) that I then try to marshall. If I don't pass the schema to the
marshaller (so it doesn't do validation), it generates the following
XML:

<Product xmlns="http://com/infopia/webservices/types/2"
xmlns:ns2="http://com.infopia.webservices/types/2"/>

which is as I would expect. However, if I give the attached schema to
the marshaller (so it does validation), I get the following exception:

javax.xml.bind.MarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration
of element 'Product'.]
        at
javax.xml.bind.MarshalException.<init>(MarshalException.java:54)
        at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:331
)
        at
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:2
58)
        at
org.springframework.oxm.jaxb.Jaxb2Marshaller.marshal(Jaxb2Marshaller.jav
a:359)
        ... 8 more
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the
declaration of element 'Product'.
        at
com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseExcept
ion(Util.java:109)
        at
com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandlerAdaptor.e
rror(ErrorHandlerAdaptor.java:104)
        at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XML
ErrorReporter.java:382)
        at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XML
ErrorReporter.java:317)
        at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStar
tElement(XMLSchemaValidator.java:1944)
        at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startEleme
nt(XMLSchemaValidator.java:705)
        at
com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.
startElement(ValidatorHandlerImpl.java:335)
        at
org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
        at
com.sun.xml.bind.v2.runtime.output.SAXOutput.endStartTag(SAXOutput.java:
124)
        at
com.sun.xml.bind.v2.runtime.output.ForkXmlOutput.endStartTag(ForkXmlOutp
ut.java:102)
        at
com.sun.xml.bind.v2.runtime.XMLSerializer.endAttributes(XMLSerializer.ja
va:302)
        at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.j
ava:680)
        at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementB
eanInfoImpl.java:151)
        at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementB
eanInfoImpl.java:185)
        at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBea
nInfoImpl.java:305)
        at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBea
nInfoImpl.java:313)
        at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBea
nInfoImpl.java:71)
        at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java
:490)
        at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328
)
        ... 10 more


I'm using Spring Web Services, so I can't (easily) give you all the code
leading up to the marshalling, but I'm trying to serialize:

new JAXBElement<Product>(new
QName("http://com/infopia/webservices/types/2", "Product"),
Product.class, new Product())

Thanks in advance for any help,
Greg