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