This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unmarshall with JAXB Error

 
Jon Christensen
Greenhorn
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?

Thanks,

Jon
 
Peer Reynders
Bartender
Posts: 2968
6
  • 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.

  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic