• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalid byte 1 of 1-byte UTF-8 sequence

 
rajanikanth bhagavan kanth
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
In my application while parsing the xml im getting this error.

Invalid byte 1 of 1-byte UTF-8 sequence

Is this error due to my code problem??
I'm getting the xml file with some third party API.

Regards
Bhagavan R
 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rajanikanth bhagavan kanth:
Is this error due to my code problem??
Probably. The error message says that you are reading the XML using the UTF-8 encoding, but it was produced using some other encoding, I think. You should first check that when you give the XML document to the parser, you don't enforce an encoding that might be incorrect by using a Reader of any kind. Use an InputStream if at all possible.

Or it's possible that the person who produced the XML document made that kind of error, and it is really malformed. But if you have to ask, it's a good idea to check your code first. Post your parsing code if you like.
 
rajanikanth bhagavan kanth
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here is my code..Its working fine some times but getting error some times.defnetly error due to thirdparty xml file but i want to kow how to fix that one

Thnks
[ November 27, 2008: Message edited by: Paul Sturrock ]
 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code would be more readable if you enclosed in the "CODE" tags. (There's a button for creating them.) Let me remind you, I asked you to check whether you were using Readers or InputStreams or what as input to your parser, didn't I? So... which is it? Have a look at the code you posted and see if you can tell from that.

Does that help? If not, post some relevant code.
[ November 26, 2008: Message edited by: Paul Clapham ]
 
rajanikanth bhagavan kanth
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes im passing InputStream as input for that parser




So can you please tell me what is the mistake in my code

Regards
Bhagavan
 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, you are getting the data from HTTP. There's a special rule in that case: the charset you should use is the charset declared on the response and not the charset declared in the document.

So the first thing you have to do is find the response's charset. Go through the headers from the response and you might find something like this:
Content-Type: text/xml; charset=windows-1252

Extract the charset from it. Then wrap your InputStream in an InputStreamReader with that charset and pass the InputStreamReader to the parser.
 
rajanikanth bhagavan kanth
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I will try the same thing and let you the status.

Regards,
Bhagavan R.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic