Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10371
  • Last Modified:

Java XML Parse error using UTF-8

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
cmercado_miranda
Asked:
cmercado_miranda
  • 3
  • 2
1 Solution
 
CEHJCommented:
>>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
 
cmercado_mirandaAuthor Commented:
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
 
CEHJCommented:
>>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
 
cmercado_mirandaAuthor Commented:
Yeap. that  whas the porblem.... I for the output of the php file using the utf-8encode() and the java works fine

Thanks!
0
 
CEHJCommented:
:-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now