tags:

views:

39

answers:

3

We have a java desktop application that uses JAXB to generate an XML file which is then read by a .Net application and stored in a SQL server database.

We're finding that carriage returns in Java and not coming over as carriage return/line feeds in .Net/SQL.

Is there a way to tell Java or Jaxb to include both the carriage return and line feed. Is there a way to get .Net to put them in. Would a CDATA block help?

Thanks.

+1  A: 

How exactly are you creating the XML file? Does the data pass through a PrintStream at any point? If so, then maybe that's the point at which the system-dependent line separators are introduced.

And where exactly are the problematic newlines? Inside a text element? Or between XML tags? If it's the former, then you should be focusing on the code that builds the text, if the latter, then it's the XML generation library.

Mike Baranczak
So we have a Java/Swing ui (text boxes) which is bound to objects using the jgoodies framework. We use Jaxb to "save" the objects to an xml file. The xml file is then imported into .net using xsd to a set of objects. Those objects in turn are manually persisted to a sql database. At no point that I'm aware of are we going through a PrintStream.
matt eisenberg
A: 

You could address this by having JAXB not add the indents:

Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);  // DEFAULT

If you are using the JAXB class to save to XML it will automatically format the document. To remove formatting don't do the following, simply use the above approach:

JAXB.marshal(object, System.out);

You could also try another JAXB implementation. I lead the MOXy JAXB implementation. When our implementation formats the document the following is used

System.getProperty("line.separator");
Blaise Doughan
we tried this and it didn't help. any other ideas? It's too late for us to use MOXy JAXB. Thanks.
matt eisenberg
Are the special characters related to content or formatting? If they are related to user supplied content you will need to convert them yourself, if they are related to formatting and you have not enabled (or disabled) this JAXB feature then some other stage is supplying the formatting.
Blaise Doughan
they are related to user supplied content
matt eisenberg
A: 

We ended up fixing them on the .net side.

We pass each string through a function that does a replace of vblf with vbcrlf. Seems to work so far.

matt eisenberg