Hallo zusammen,
ich probiere seit 1 Tag diese XML Datei mit Java auszulesen:
[XML]<?xml version="1.0"?>
<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
<forecast_information>
<city data="Zürich District, Canton of Zürich"/>
<postal_code data="Zuerich"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2011-01-12"/>
<current_date_time data="2011-01-12 17:20:00 +0000"/>
<unit_system data="US"/>
</forecast_information>
<current_conditions>
<condition data="Light rain"/>
<temp_f data="43"/>
<temp_c data="6"/>
<humidity data="Humidity: 81%"/>
<icon data="/ig/images/weather/mist.gif"/>
<wind_condition data="Wind: S at 9 mph"/>
</current_conditions>
<forecast_conditions>
<day_of_week data="Wed"/>
<low data="41"/>
<high data="46"/>
<icon data="/ig/images/weather/chance_of_rain.gif"/>
<condition data="Chance of Rain"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Thu"/>
<low data="41"/>
<high data="51"/>
<icon data="/ig/images/weather/chance_of_rain.gif"/>
<condition data="Chance of Rain"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Fri"/>
<low data="39"/>
<high data="48"/>
<icon data="/ig/images/weather/sunny.gif"/>
<condition data="Clear"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Sat"/>
<low data="39"/>
<high data="50"/>
<icon data="/ig/images/weather/chance_of_rain.gif"/>
<condition data="Chance of Rain"/>
</forecast_conditions>
</weather>
</xml_api_reply>
[/XML]
mit diesem .java File probiere ich es sie auszulesen, aber es klappt nicht:
(Das File beinhaltet mehrere Versuche an den roten Wert als String zu kommen)
Ich möchte nur den rot markierten Wert aus dem XML auslesen. Der Rest ist für mein Programm nicht wichtig.
Wäre sehr froh um Hilfe!
Gruss
ich probiere seit 1 Tag diese XML Datei mit Java auszulesen:
[XML]<?xml version="1.0"?>
<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
<forecast_information>
<city data="Zürich District, Canton of Zürich"/>
<postal_code data="Zuerich"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2011-01-12"/>
<current_date_time data="2011-01-12 17:20:00 +0000"/>
<unit_system data="US"/>
</forecast_information>
<current_conditions>
<condition data="Light rain"/>
<temp_f data="43"/>
<temp_c data="6"/>
<humidity data="Humidity: 81%"/>
<icon data="/ig/images/weather/mist.gif"/>
<wind_condition data="Wind: S at 9 mph"/>
</current_conditions>
<forecast_conditions>
<day_of_week data="Wed"/>
<low data="41"/>
<high data="46"/>
<icon data="/ig/images/weather/chance_of_rain.gif"/>
<condition data="Chance of Rain"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Thu"/>
<low data="41"/>
<high data="51"/>
<icon data="/ig/images/weather/chance_of_rain.gif"/>
<condition data="Chance of Rain"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Fri"/>
<low data="39"/>
<high data="48"/>
<icon data="/ig/images/weather/sunny.gif"/>
<condition data="Clear"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Sat"/>
<low data="39"/>
<high data="50"/>
<icon data="/ig/images/weather/chance_of_rain.gif"/>
<condition data="Chance of Rain"/>
</forecast_conditions>
</weather>
</xml_api_reply>
[/XML]
mit diesem .java File probiere ich es sie auszulesen, aber es klappt nicht:
(Das File beinhaltet mehrere Versuche an den roten Wert als String zu kommen)
Java:
package Weather;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class XMLReader2 {
public static void main(String argv[]) {
try {
File file = new File("MyXMLFile2.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
System.out.println(doc.getDocumentElement().getNodeName());
NodeList n = doc.getDocumentElement().getChildNodes();
System.out.println(n.item(0).getNodeName());
System.out.println("Title: " + doc.getDocumentElement().getNodeName());
String b = doc.getDocumentElement().getChildNodes().item(0).getNodeName();
System.out.println(b);
NodeList nl1 = doc.getElementsByTagName("current_conditions");
Element firstelement = (Element) nl1.item(0);
NodeList nl11 = firstelement.getChildNodes();
System.out.println(firstelement.getNodeName());
System.out.println(((Node) nl11.item(0)).getNodeName());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Ich möchte nur den rot markierten Wert aus dem XML auslesen. Der Rest ist für mein Programm nicht wichtig.
Wäre sehr froh um Hilfe!
Gruss