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());
}
} |
Partager