• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Unmarshall with JAXB Error

Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?


Posts: 2968
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

    Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
    the value of filler advertising in 2020
      Bookmark Topic Watch Topic
    • New Topic