Solved

Java XML Parse error using UTF-8

Posted on 2007-12-03
5
10,366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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. 
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

724 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