Solved

Java XML Parse error using UTF-8

Posted on 2007-12-03
5
10,357 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now