Hi,
I tried your sample inside Eclipse (I had to change the file encoding to
UTF-8 in the "Property" pop-up dialog).
package test;
import org.junit.Assert;
import commonj.sdo.DataObject;
import commonj.sdo.helper.XMLDocument;
import commonj.sdo.helper.XMLHelper;
public class TestChinese {
public static void main(String[] args) {
String s =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns:StringE
xmlns:ns=\"http://test/choice\">中文</ns:StringE>";
XMLDocument doc = XMLHelper.INSTANCE.load(s);
DataObject o = doc.getRootObject();
//here we'll load the xml success; and the assertion will passed
//
Assert.assertTrue(((SimpleAnyTypeDataObjectImpl)o).getValue().toString().indexOf("中文") >= 0);
String xml = XMLHelper.INSTANCE.save(o, "http://ns", "root");
//assertion failed, here we'll got a xml (using utf-8 encoding)
contains error character code.
Assert.assertTrue(xml.indexOf("中文") >= 0);
System.out.println(xml);
}
}
And I can see the result as:
<?xml version="1.0" encoding="UTF-8"?>
<ns:root xmlns:ns="http://ns">中文</ns:root>
Thanks,
Raymond
--------------------------------------------------
From: "ext2" <[email protected]>
Sent: Thursday, March 11, 2010 4:47 AM
To: <[email protected]>
Subject: Tuscany SDO-Java implementation failed to save sdo(contains
multi-byte character) to xml
Hi
The tuscany sdo 's java implementation can load xml (contains
muti-byte code) correct. But cannot save the sdo (has Chinese character
value) to xml correctly;
For example:
I could load a xml(utf-8 encoding specified) which contains Chinese
character to sdo correctly. But it will failed to save it to xml (using
utf-8 encoding).
I have ensured using correct "javac -encoding " to compile the
source java file.
Code sample:
String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns:StringE
xmlns:ns=\"http://test/choice\">中文</ns:StringE>";
XMLDocument doc= scope.getXMLHelper().load(s);
DataObject o = doc.getRootObject();
//here we'll load the xml success; and the assertion will passed
assertTrue(((SimpleAnyTypeDataObjectImpl)o).getValue().toString().indexOf("
中文") >= 0);
String xml = scope.getXMLHelper().save(o, uri, name);
//assertion failed, here we'll got a xml (using utf-8 encoding) contains
error character code.
assertTrue(xml.indexOf("中文") >= 0);