The moose likes Web Services and the fly likes Unmarshall with JAXB Error Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Web Services
Reply Bookmark "Unmarshall with JAXB Error" Watch "Unmarshall with JAXB Error" New topic
Author

Unmarshall with JAXB Error

Jon Christensen
Greenhorn

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?

Thanks,

Jon
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
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.


  • "Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
    Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
     
     
    subject: Unmarshall with JAXB Error
     
    Threads others viewed
    From .Net DataTable to Java which object?
    What is "NewDataSet" in XSD file?
    New Fields in XML
    Handling response in Axis2 ADB clasess
    Consuming a .NET Typed DataSet from Java
    WebSphere development made easy
    without the weight of IBM tools
    http://www.myeclipseide.com

    cast iron skillet 49er

    more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture