Bonjour,

Je souhaite réaliser un parser SAX depuis une URL.
Je souhaite récupérer les coordonnées d'un lieu sur google maps.
Dans mon cas j'ai un message d'erreur :
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 3-byte UTF-8 sequence.
Cela est certainement dû au lieu que je recherche, le document XML contient des accents.
Si je change le lieu en question pour qu'il n'y ai aucun accent dans le document XML je n'ai plus aucun problème (par ex: changé gieres par paris dans l'url). Or je serai amené à avoir des accents.

Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.*;
import java.net.MalformedURLException;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory; 
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
 
 
public class test3 extends DefaultHandler {
	private boolean inText=false;
	private StringBuffer result=new StringBuffer();
	public void startElement(String namespaceURI, String localName,
	              String qName, Attributes atts) {
		  if(qName.equals("coordinates"))
			  inText=true;
	}
	public void endElement(String namespaceURI, String localName, String qName) {
		if(qName.equals("coordinates"))
			  inText=true;
	}
	public void characters(char[] ch, int start, int length) {
		  if(inText)
			  result.append(ch, start, length);
	}
	// methode specifique
	public String getText() {
		return result.toString();
	}
	public static void main(String[] args) throws MalformedURLException, IOException, SAXException, ParserConfigurationException{
		test3 handler = new test3();
		SAXParserFactory factory =SAXParserFactory.newInstance();
		factory.setValidating(true);
		SAXParser parser;
		parser = factory.newSAXParser();
		parser.parse("http://maps.google.com/maps/geo?q=gieres,france&output=xml&sensor=true_or_false&key=abcdefg", handler);
		System.out.println(handler.getText());
	}
}
Merci pour votre aide