Solved

Java XML Parse error using UTF-8

Posted on 2007-12-03
5
10,359 Views
Last Modified: 2013-11-23
Hi,
      I have a java porgram that read an XML document from a url. here is an excerp from the XML:

<?xml version="1.0" encoding="UTF-8"?>
<items >
<item font-face="Arial" font-size="30" font-color="16777215">
<![CDATA[BON]]></item><item font-face="Arial" font-size="30" font-color="16777215"><![CDATA[* Disfruta de tus programas favoritos en WAPA Mývil en tu celular de Claro. * * Textea al 29960 * 18+ solamente * Más información www.wapa.tv *]]>
</item>
</items>

 The code that's is reading the file is the following:

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse("http://65.38.219.91/29960/test/getmessages2.php");

but I got the follwing error when the code have latin charcter like é or á

com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 4-byte UTF-8 sequence.

What can I do?
0
Comment
Question by:cmercado_miranda
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 20397407
>>Invalid byte 2 of 4-byte UTF-8 sequence.

It probably *isn't* encoded as UTF-8. You need to read it with the correct encoding
0
 

Author Comment

by:cmercado_miranda
ID: 20397441
how can this be possible if the <?xml version="1.0" encoding="UTF-8"?> say this?

this XML is generated dynamically by a php file, do I need to put something in the content type of the php file to?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20397524
>>how can this be possible if the <?xml version="1.0" encoding="UTF-8"?> say this?

That can say whatever it wants. It doesn't mean it's true
0
 

Author Comment

by:cmercado_miranda
ID: 20397651
Yeap. that  whas the porblem.... I for the output of the php file using the utf-8encode() and the java works fine

Thanks!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20399303
:-)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 63
runtime exception 2 28
Fulfillment API php code sample 1 41
what are list of ebay api errors 1 19
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question