Thanks Raymond:

I tried your sample code again, as exactly as you done in eclipse. But the
error still exists.
        
I have tried the Tuscany-sdo-1.1.1-release and the snap-shot source code
from svn of tuscany. They both have such error.

        Maybe this error is caused by the other librarys used by Tuscany
sdo. Could you help me to exports your project's ant-build for me? Then I
could check the different as mine.

Following is the library list used by my project: 
stax-api-1.0.1.jar, backport-util-concurrent-3.0.jar, wstx-asl-3.2.1.jar,
common-2.2.3.jar, ecore-2.2.3.jar, ecore-change-2.2.3.jar,
ecore-xmi-2.2.3.jar, xsd-2.2.3.jar, codegen-2.2.3.jar,
codegen-ecore-2.2.3.jar;

Best regards


        
=============Original=====================

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().ind
exOf("中文") >= 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);
>
>
> 


Reply via email to