0
我有一个XmlObject,它具有我需要的正确值。 例如:1½-2Y在ByteArrayOutputStream转换期间添加的特殊字符
但是,当我试图将其转换成流的字节,结果我看到1½-2Y。
样品的编号:
import org.apache.xmlbeans.XmlObject;
Class MyClass implements XmlBuilder<T> {
protected final String serializeToXml(XmlObject xmlObject) {
ByteArrayOutputStream os = null;
try {
os = new ByteArrayOutputStream();
xmlObject.save(os,createXmlOptions()); /Its adding a special char here
return os.toString();
}
}
protected final XmlOptions createXmlOptions() {
final XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setValidateOnSet();
xmlOptions.setCharacterEncoding(UTF_8_ENCODING);
return xmlOptions;
}
}
它工作,我改变了我的byteArrayOutputStream从os.toString()到新的字符串(os.toByteArray(),UTF_8_ENCODING)。谢谢 :) – Mahi