0

I am sending xml serialized object to the client from server using TCP socket. I am having some problem while converting byte array to xml string. I dont know if I am not using correct decoder but when the byte array is recieved in the client end, the xml string is prefixed by '?'. Thus first line of my xml string is becoming something like ?<?xml version="1.0" encoding="utf-8"?> which I cannot deserialize as it is no more a valid xml.

I tried both UTF-8 and Ascii encoding.

Any input will be highly appreciated.

thanks,

Bibek Dawadi

1
  • Could you show the code related to sending and receiving data from the socket? Commented Feb 25, 2011 at 15:35

2 Answers 2

1

If you get a ? in front of the string it means you have saved it as UTF8. Most likely you have serialized into UTF (UTF8?), but at some point you are converting it to ASCII. I'd guess after receive.

Avoiding converting it to string anywhere and work directly on the byte-array instead and it should be ok.

Background:
Wikipedia article on UTF8.
ASCII is only 7-bit bytes, so any byte in the range 128-255 is replaced when converting to ASCII.
RFC3629: See section 6: BOM

Sign up to request clarification or add additional context in comments.

1 Comment

But I cannot have XML directly coverted to byte[] because I am implementing message frame using delemiter. That is why I am serializing the object, getting xml string, prefix and suffix this xml string with delemiter to have new string, convert to byte[] and then send it over TCP/IP socket. While converting final string to byte[] I am using UTF-8 Encoding and while converting byte[] back to string also I am using UTF-8 Encoding.
0

ASCII will replace unrecognized bytes with ?. It's possible that this is what is happening.

It's difficult to tell from your question where the problem might be; posting your sending and receiving code would help. I also have some advice on my blog for sending XML over TCP/IP.

1 Comment

Thanks Stephen. But I cannot have XML directly coverted to byte[] because I am implementing message frame using delemiter. That is why I am serializing the object, getting xml string, prefix and suffix this xml string with delemiter to have new string, convert to byte[] and then send it over TCP/IP socket. While converting final string to byte[] I am using UTF-8 Encoding and while converting byte[] back to string also I am using UTF-8 Encoding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.