Ich hat versucht, einen Code für Wetter-App, und ich habe diesen Fehler geschrieben:Wie zu lösen - Der Elementtyp Meta muss durch den entsprechenden End-Tag beendet wird</meta>
org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 27; The element type "meta" must be terminated by the matching end-tag "". at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse (AbstractSAXParser.java:1239) at main.Weather.GoogleWeather.getWeather(GoogleWeather.java:38) at main.Main.main(Main.java:12)
Ich weiß nicht, ob ich setzen alles richtig
Mein Code:
public class GoogleWeather extends Weather{
private final String googleWeatherURL = "http://www.google.com/ig/api?weather=";
public GoogleWeather(String city, String locationPoints) throws IOException, SAXException {
super(city, locationPoints);
}
@Override
public void getWeather() {
String location = "Warsaw, PL";
String link = googleWeatherURL + location;
link = link.replace(" ", "%20");
try {
URL urlObject = new URL(link);
InputStream in = urlObject.openStream();
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
XMLHandler xmlHandler = new XMLHandler();
xmlReader.setContentHandler((ContentHandler) xmlHandler);
InputSource inSource = new InputSource(in);
xmlReader.parse(inSource);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (SAXException se) {
se.printStackTrace();
}
Und
public class XMLHandler extends DefaultHandler {
private ArrayList<Integer> night = new ArrayList<Integer>();
private ArrayList<Integer> day = new ArrayList<Integer>();
private ArrayList<String> days = new ArrayList<String>();
private ArrayList<String> conditions = new ArrayList<String>();
public XMLHandler() {
super();
}
@Override
public void startDocument() {
System.out.println("Start document");
}
@Override
public void endDocument() {
System.out.println("End document");
}
@Override
public void startElement(String uri, String name, String qName, Attributes atts) {
if (qName.compareTo("day_of_week") == 0) {
String day = atts.getValue(0);
System.out.println("Day: " + day+ " ; ");
this.days.add(day);
}
if (qName.compareToIgnoreCase("low") == 0) {
int night = Integer.parseInt(atts.getValue(0));
System.out.print("Low: " + night + " ; ");
this.night.add(night);
}
if (qName.compareToIgnoreCase("high") == 0) {
int high = Integer.parseInt(atts.getValue(0));
System.out.print("High: " + high + " ; ");
this.day.add(high);
}
if (qName.compareToIgnoreCase("condition data") == 0) {
String conditions = atts.getValue(0);
System.out.print("Conditions: " + conditions + " ; ");
this.conditions.add(conditions);
}
}
}
Vielen Dank im Voraus.