Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » [Moxy] Simple unmarshalling and marshalling changes xml
[Moxy] Simple unmarshalling and marshalling changes xml [message #1058464] Tue, 14 May 2013 09:11 Go to next message
moritz du is currently offline moritz duFriend
Messages: 98
Registered: February 2010
Member
I have to write some xml-Data of specific format (see attachment). Since there are some constant attributes (especially in root element) i created a template (genrate from xsd from eclipse).

the Problem is if i unmarshal and marshal this template the content changes:

Input:
<?xml version="1.0" encoding="UTF-8"?>
<invoice:response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:invoice="http://www.forum-datenaustausch.ch/invoice" xmlns="http://www.forum-datenaustausch.ch/invoice" xsi:schemaLocation="http://www.forum-datenaustausch.ch/invoice generalInvoiceResponse_440.xsd" language="de">
  <invoice:processing>
    <invoice:transport from="" to="">
      <invoice:via sequence_id="0" via=""/>
    </invoice:transport>
  </invoice:processing>
  <invoice:payload response_timestamp="0">
    <invoice:invoice request_date="2001-12-31T12:00:00" request_id="" request_timestamp="0"/>
  </invoice:payload>
</invoice:response>


Output:
<?xml version="1.0" encoding="UTF-8"?>
<response xmlns="http://www.forum-datenaustausch.ch/invoice" xmlns:ns1="http://www.w3.org/2000/09/xmldsig#" xmlns:ns0="http://www.w3.org/2001/04/xmlenc#" language="de">
   <processing>
      <transport from="" to="">
         <via via="" sequence_id="0"/>
      </transport>
   </processing>
   <payload response_timestamp="0">
      <invoice request_timestamp="0" request_date="2001-12-31T12:00:00.0" request_id=""/>
   </payload>
</response>


Some of the attributes are missing and the name space prefix. i don't know if this changes are relevant (in respect to xsd) but i want as near as possible to the examples i got.
how to get moxy to leave all that is not touched unchanged (i think the attribute order really doesn't matter?)?

thx in advance

[Updated on: Tue, 14 May 2013 09:12]

Report message to a moderator

Re: [Moxy] Simple unmarshalling and marshalling changes xml [message #1058567 is a reply to message #1058464] Tue, 14 May 2013 13:29 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

You can use the JAXB_SCHEMA_LOCATION property on the Marshaller to have a schemaLocation output when marshalling.

marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.forum-datenaustausch.ch/invoice generalInvoiceResponse_440.xsd");

Otherwise the namespace qualification of the documents is equivalent (local names and namespaces are the same) only the prefixes are different. Is this causing problems in your application?
Re: [Moxy] Simple unmarshalling and marshalling changes xml [message #1058580 is a reply to message #1058567] Tue, 14 May 2013 13:53 Go to previous messageGo to next message
moritz du is currently offline moritz duFriend
Messages: 98
Registered: February 2010
Member
thx blaise this sets the attribute at least.

the overall problem is that the xml output goes somewhere else (the xsd is a industry standard in switzerland) and i don't know if this causes any problems somewhere. (i don't know if all consumers use generated code or use handwritten stuff that relies on "invoice..."). I guess it is not enough to rely on validity.

The only thing i know is that all examples i saw look like the output that eclipse generates from xsd (attributes in root element and all prefixed with "invoice").

Is there any way to let moxy those parts untouched or let it rebuild it like all the other xml-generators do?

So if i set the attributes in root manually i only need moxy to write "invoice" as prefix - is this possible?

[Updated on: Tue, 14 May 2013 13:57]

Report message to a moderator

Re: [Moxy] Simple unmarshalling and marshalling changes xml [message #1058864 is a reply to message #1058464] Wed, 15 May 2013 13:01 Go to previous message
moritz du is currently offline moritz duFriend
Messages: 98
Registered: February 2010
Member
perfect answer here:

http://stackoverflow.com/questions/16559889/marshalling-and-unmarshalling-changes-xml-using-moxy
Previous Topic:Map<Integer, BigDecimal> causes NPE because it is backed by a Hashtable
Next Topic:[Moxy] How to efficiently create (valid) xml for given Schema
Goto Forum:
  


Current Time: Sat Dec 20 18:11:12 GMT 2014

Powered by FUDForum. Page generated in 0.07693 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software