Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

UTF-8 Encoding And PB10.2

247 views
Skip to first unread message

Dave Haygood

unread,
Apr 19, 2005, 4:50:39 PM4/19/05
to
I am feeling really stupid, but could someone explain to me why the
following works?

I am converting our applications from PB9.02 to PB 10.2. We have an
xml transmission section to various suppliers. Works great in PB9.

Because it is a B2B standard UTF-8 encoding is required. I understand
that PB10 has changed to Unicode, so by default xml exported from
datawindows is in UTF-16LE format and has to be converted to UTF-8
before I transmit it to our B2B partners.

So, I thought I could just take a string (xml) which was filled by the
following statement:

l_stest = dw_1.object.datawindow.data.xml

Then convert it from UTF-16LE to UTF-8

l_stest = String( Blob(l_stest), EncodingUTF8!)

and transmit. Of course this didn't work! So I tried various
combinations and found one that DID work. So could someone explain my
ignorance. This is what works:

l_stest = String ( Blob(l_stest, EncodingUTF8!), EncodingUTF16LE!)


Wouldn't this convert the string to a blob with UTF-8 encoding, and
then convert it back to UTF-16LE? End result I'm sending out UTF-16LE?

Thanks,
Baffled Dave

Roy Kiesler [TeamSybase]

unread,
Apr 19, 2005, 5:21:00 PM4/19/05
to
String ( Blob(l_stest, EncodingUTF8!), EncodingUTF8!)

... looks better to me -- Blob(l_test, EncodingUTF8!) will create a
UTF-8 encoded blob from the UTF-16LE string. Then, String(<UTF8 blob>),
EncodingUTF8!) will convert the UTF-8 blob to a UTF-8 string for your
transmission.

--
Roy

Dave Haygood

unread,
Apr 19, 2005, 8:22:58 PM4/19/05
to
I Know!, wouldn't you think? ... Doesn't Work!

Dumbfounded Dave

On 19 Apr 2005 14:21:00 -0700, "Roy Kiesler [TeamSybase]"

Roy Kiesler [TeamSybase]

unread,
Apr 20, 2005, 11:48:24 AM4/20/05
to

"Doesn't work" -- do you mean the string remains UTF16-encoded, or are
you getting an error?

An isolated test case will be helpful here.

--
Roy

Dave Haygood

unread,
Apr 20, 2005, 3:42:33 PM4/20/05
to
On 20 Apr 2005 08:48:24 -0700, "Roy Kiesler [TeamSybase]"
<roy.k...@teamsybase.com> wrote:

>Dave Haygood wrote:
>> I Know!, wouldn't you think? ... Doesn't Work!
>>
>> Dumbfounded Dave
>>
>> On 19 Apr 2005 14:21:00 -0700, "Roy Kiesler [TeamSybase]"
>> <roy.k...@teamsybase.com> wrote:
>>
>>
>>>String ( Blob(l_stest, EncodingUTF8!), EncodingUTF8!)
>>>
>>>... looks better to me -- Blob(l_test, EncodingUTF8!) will create a
>>>UTF-8 encoded blob from the UTF-16LE string. Then, String(<UTF8 blob>),
>>>EncodingUTF8!) will convert the UTF-8 blob to a UTF-8 string for your
>>>transmission.
>>
>>
>
>"Doesn't work" -- do you mean the string remains UTF16-encoded, or are
>you getting an error?
>
>An isolated test case will be helpful here.

Ok, I figured it out, sort of. I get an error returned from the server
to answer your question. Here is a simplified example I used to test,
and in writing it up I figured out what I did wrong. Here is the
sample that went wrong:

String l_surl, l_sxml, l_sheader
Long l_llen
Int l_ierror
Blob l_blob

l_sxml = "..."

l_sxml = String(Blob(l_sxml, EncodingUTF8!), EncodingUTF16LE!)
l_blob = Blob(l_sxml)

l_surl = "..."
l_llen = Len(l_blob)
l_sheader = "Content-Type: text/xml~nContent-Length: " +
String(l_llen) + "~n~n"

l_ierror = i_Inet_base.PostURL(l_surl, l_blob, l_sheader, 0,
iuo_internetdata)
If l_ierror <> 1 then MessageBox("Post URL Error", "Error = " +
string(l_ierror))


The problem is I forgot that for PostURL I convert the string to blob
again for transmission. This is not the case when using Winhttp
function calls (The actual app uses a secure connection HTTPS).

Since I didn't include an encoding on the blob statement, the system
seems to have re-encoded it using the last blob statement's arguments.
I should have done it like this:

l_sxml = "..."

l_blob = Blob(l_sxml, EncodingUTF8!)

...

This works in the test example, and :

l_sxml = String(Blob(l_sxml, EncodingUTF8!), EncodingUTF8!)

works in the actual application because the string is passed in
Winhttp not a blob. Thanks for helping me work through this, I knew I
was not "getting" something.

Dave


Roy Kiesler [TeamSybase]

unread,
Apr 20, 2005, 4:36:50 PM4/20/05
to
Excellent! Glad to see you're back in business

--
Roy

0 new messages