0

I have a Java XML String where the values of some properties are wrapped in <![CDATA ... ]]>. I created a class called Root that I have used to unmarshal the string into an object successfully. I now want to convert it back into the same string (after I changed some values). JAXB.unmarshal(new StringReader(XML), Root.class);

The issue I have is the following:

  1. The CDATA wrapping is removed from all of the values (the original string had it and I want to keep it when I marshal it back to string from object).
  2. The header includes standalone attribute, which was not included in the original string (I want it removed and replaced with only version and encoding, as was in the original string).
  3. I have self closing tags in the original XML string, but they are removed when I am marshalling back into a string.
  4. Formatting is removed and I get a single line when I marshal. I want it to be formatted.

I am using JAXB 4.0 and Java 17.

yaserso
  • 2,638
  • 5
  • 41
  • 73
  • for point 3, you need to set nillable = true inside your @XmlElement annotation. for point 4, [https://stackoverflow.com/questions/139076/how-to-pretty-print-xml-from-java] refer this page – LMH May 14 '23 at 18:59

0 Answers0