If you want generated XML to contain this kind of
characters as it is
, then XML 1.1 specification might help.
Castor can be configured to marshal into XML 1.1 with custom org.exolab.castor.xml.XMLSerializerFactory and org.exolab.castor.xml.Serializer implementations:
package com.foo.castor;
......
import org.exolab.castor.xml.BaseXercesOutputFormat;
import org.exolab.castor.xml.Serializer;
import org.exolab.castor.xml.XMLSerializerFactory;
import org.xml.sax.DocumentHandler;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XML11Serializer;
@SuppressWarnings("deprecation")
public class CastorXml11SerializerFactory implements XMLSerializerFactory {
private static class CastorXml11OutputFormat extends BaseXercesOutputFormat{
public CastorXml11OutputFormat(){
super._outputFormat = new OutputFormat();
}
}
private static class CastorXml11Serializer implements Serializer {
private XML11Serializer serializer = new XML11Serializer();
@Override
public void setOutputCharStream(Writer out) {
serializer.setOutputCharStream(out);
}
@Override
public DocumentHandler asDocumentHandler() throws IOException {
return serializer.asDocumentHandler();
}
@Override
public void setOutputFormat(org.exolab.castor.xml.OutputFormat format) {
serializer.setOutputFormat((OutputFormat)format.getFormat());
}
@Override
public void setOutputByteStream(OutputStream output) {
serializer.setOutputByteStream(output);
}
}
@Override
public Serializer getSerializer() {
return new CastorXml11Serializer();
}
@Override
public org.exolab.castor.xml.OutputFormat getOutputFormat() {
return new CastorXml11OutputFormat();
}
}
in castor.properties file globally
org.exolab.castor.xml.serializer.factory=com.foo.castor.CastorXml11SerializerFactory
org.exolab.castor.xml.version=1.1
or set these two properties by setCastorProperties method of your particular CastorMarshaller.
Please be advised, however, that XML 1.1 is not accepted by browsers and not all XML parsers can parse XML 1.1 out of the box.