users@jaxb.java.net

RE: validation issue

From: Greg Thoenen <gthoenen_at_infopia.com>
Date: Thu, 10 Jan 2008 11:45:05 -0700

Doh! I figured out that problem. I instead needed to marshall:

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

(i.e. use the correct namespace)! However, even though I think that's
more correct, it still doesn't work. It now generates:

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

but if given the schema, its complaint is:

Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the
declaration of element 'ns2:Product'.


I have a feeling it's another namespace issue, but it's not clear to me
what that would be. Any help would be appreciated - sorry for not
figuring out the above part beforehand.

Thanks,
Greg


> -----Original Message-----
> From: Greg Thoenen [mailto:gthoenen_at_infopia.com]
> Sent: Thursday, January 10, 2008 10:49 AM
> To: users_at_jaxb.dev.java.net
> Subject: validation issue
>
> 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(MarshallerImp
> l.java:331
> )
> at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerI
> mpl.java:2
> 58)
> at
> org.springframework.oxm.jaxb.Jaxb2Marshaller.marshal(Jaxb2Mars
> haller.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.toSAXP
> arseExcept
> ion(Util.java:109)
> at
> com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandle
> rAdaptor.e
> rror(ErrorHandlerAdaptor.java:104)
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.repor
> tError(XML
> ErrorReporter.java:382)
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.repor
> tError(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.ValidatorHa
> ndlerImpl.
> startElement(ValidatorHandlerImpl.java:335)
> at
> org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
> at
> com.sun.xml.bind.v2.runtime.output.SAXOutput.endStartTag(SAXOu
> tput.java:
> 124)
> at
> com.sun.xml.bind.v2.runtime.output.ForkXmlOutput.endStartTag(F
> orkXmlOutp
> ut.java:102)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.endAttributes(XMLSer
> ializer.ja
> va:302)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSe
> rializer.j
> ava:680)
> at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBod
> y(ElementB
> eanInfoImpl.java:151)
> at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBod
> y(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(XMLSeria
> lizer.java
> :490)
> at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImp
> l.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
>
>