xstream is converting & to & when converting from xml to Java Objects.
I don’t want this to happen. How shall I do it?
XStream xstream = new XStream(new DomDriver());
xstream.processAnnotations(HelpConfigVO.class);
xstream.processAnnotations(ProductVO.class);
xstream.processAnnotations(PackageVO.class);
xstream.addImplicitCollection(HelpConfigVO.class, "packages");
configVO = (HelpConfigVO)xstream.fromXML(helpConfigData);
Secondly, The output XML I am getting from xstream is not formatted. How do I format my xml to make it readable?
As it should. It would be broken if it didn’t
Why? The
"&"in the XML means"&".No valid XML parser will do this for you because it is an egregious violation of the XML spec. In theory, you could hack an open source XML parser to do this abominable act … but I’d strongly advise against it.
If correct behavior in the parser is causing you problems, you’ve got a flaw in your application design. You should do something like:
not parsing the XML – store it as character sequence, OR
reinsert the character entities by applying the XML escape mapping to the text before you use it.