Generated Java XML with special characters in .Net / SQL

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

We find that carriage returns in Java do not happen like carriage / line returns in .Net / SQL.

Is there a way to tell Java or Jaxb to include both carriage return and line. Is there a way to get .Net to insert them. Can a CDATA block help?

Thanks.

+4
source share
4 answers

We have finished fixing them on the .net side.

We pass each line through a function that replaces vblf with vbcrlf. Seems to work so far.

0
source

How exactly do you create an XML file? Is data transferred through PrintStream at any time? If so, then it is possible that the point at which system line separators are entered.

And where exactly is the problematic news? Inside a text element? Or between XML tags? If this is the first, then you should focus on the code that builds the text, if the latter, then this is an XML generation library.

+1
source

You can refer to this if JAXB doesn't add padding:

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

If you use the JAXB class to save to XML, it automatically formats the document. To remove formatting, do not follow these steps, just use the above approach:

 JAXB.marshal(object, System.out); 

You can also try a different JAXB implementation. I lead the implementation of MOXy JAXB . When our implementation formats a document, the following is used.

 System.getProperty("line.separator"); 
0
source

Actually this answer by Blaise Dohan was pretty good (Myabe typo?)

 Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // Blaise wrote 'false' here 

For me it saves newlines ...

0
source

All Articles