This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Web Services and the fly likes Unmarshall with JAXB Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Unmarshall with JAXB Error" Watch "Unmarshall with JAXB Error" New topic

Unmarshall with JAXB Error

Jon Christensen

Joined: Apr 14, 2003
Posts: 21
I am using JAXB to unmarshall an xml file obtained from a web service call. The service is running on .NET and returns the xsd and then the xml. I used the xsd to generate the classes with JAXB. When I try to unmarshall the xml I am getting the following error:

The .xsd file doesn't say anything about the diffgram but it is the first element in the xml:

Can I instruct the unmarshaller to ignore the diffgr? If not what am I missing to allow me to successfully unmarshall this document?


Peer Reynders

Joined: Aug 19, 2005
Posts: 2932
It is not that simple. A DiffGram is a .NET specfic XML format (DiffGram Examples). The diffgram can contain three elements, and you are probably only interested in the first one:
  • The first element is the DataInstance that usually contains the serialized data from a System.Data.DataTable, System.Data.DataSet instance or a SQL Server database. The XSD only describes elements that occur inside this DataInstance - furthermore the contents is contaminated with {urn:schemas-microsoft-com:xml-diffgram-v1}hasChanges which identify changed rows and elements, {urn:schemas-microsoft-com:xml-diffgram-v1}hasErrors which identify rows with errors, and {urn:schemas-microsoft-com:xml-diffgram-v1}id attributes which are used by the {urn:schemas-microsoft-com:xml-diffgram-v1}before and {urn:schemas-microsoft-com:xml-diffgram-v1}errors content for referencing. Furthermore you may also find attributes from the urn:schemas-microsoft-com:xml-msdata namespace in the content. To make things even more difficult the XSD may reference the urn:schemas-microsoft-com:mapping-schema namespace for some meta-data.
  • A {urn:schemas-microsoft-com:xml-diffgram-v1}before element that contains the "before" data values of the rows and elements that were tagged with {urn:schemas-microsoft-com:xml-diffgram-v1}hasChanges.
  • A {urn:schemas-microsoft-com:xml-diffgram-v1}errors element that contains error information the of the rows that were tagged with {urn:schemas-microsoft-com::xml-diffgram-v1}hasErrors.

  • The XSD that you have doesn't define a root element that is equivalent to the containing DataInstance element - JAXB needs a document root element to work. There are many ways to approach this. One of them might be:
  • Develop an XLST transform that adds a root element and strips the extraneous references to the microsoft namespaces from the XSD. Use the transform to generate a new XSD that can be used by the JAXB binding compiler
  • Develop an XSLT transform that strips all the extraneous information and replaces the DataInstance element with the document root element specified in your XSD. Use the transform to generate a new XML document that can be used by the JAXB unmarshaller.

    I agree. Here's the link:
    subject: Unmarshall with JAXB Error
    It's not a secret anymore!