Hallo zusammen,
ich habe folgendes Java Programm:
Wenn ich den XML Stream speichere dann kommt er so raus:
[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-13"/><current_date_time data="2011-01-13 12:20:00 +0000"/><unit_system data="US"/></forecast_information><current_conditions><condition data="Mostly Cloudy"/><temp_f data="50"/><temp_c data="10"/><humidity data="Humidity: 87%"/><icon data="/ig/images/weather/mostly_cloudy.gif"/><wind_condition data="Wind: SW at 13 mph"/></current_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="41"/><high data="50"/><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/mostly_sunny.gif"/><condition data="Mostly Sunny"/></forecast_conditions><forecast_conditions><day_of_week data="Sun"/><low data="39"/><high data="48"/><icon data="/ig/images/weather/sunny.gif"/><condition data="Clear"/></forecast_conditions></weather></xml_api_reply>[/XML]
Er sollte aber beim Speichern so formatiert werden:
[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]
Wäre froh, wenn mir jemand den Java Code geben könnte um das XML File wie in der 2 Darstellung mit absätzen zu speichern.
Gruss.
ich habe folgendes Java Programm:
Java:
package Weather;
import java.beans.XMLDecoder;
import java.io.*;
import java.net.*;
public class Filesaver{
public static void main(String args[]) throws IOException{
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new
java.net.URL("http://www.google.com/ig/api?weather=Zuerich").openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream("wetter.xml");
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos);
byte[] data = new byte[1024];
int x=0;
while((x=in.read(data,0,1024))>=0){
bout.write(data,0,x);
}
bout.close();
in.close();
}
}
Wenn ich den XML Stream speichere dann kommt er so raus:
[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-13"/><current_date_time data="2011-01-13 12:20:00 +0000"/><unit_system data="US"/></forecast_information><current_conditions><condition data="Mostly Cloudy"/><temp_f data="50"/><temp_c data="10"/><humidity data="Humidity: 87%"/><icon data="/ig/images/weather/mostly_cloudy.gif"/><wind_condition data="Wind: SW at 13 mph"/></current_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="41"/><high data="50"/><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/mostly_sunny.gif"/><condition data="Mostly Sunny"/></forecast_conditions><forecast_conditions><day_of_week data="Sun"/><low data="39"/><high data="48"/><icon data="/ig/images/weather/sunny.gif"/><condition data="Clear"/></forecast_conditions></weather></xml_api_reply>[/XML]
Er sollte aber beim Speichern so formatiert werden:
[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]
Wäre froh, wenn mir jemand den Java Code geben könnte um das XML File wie in der 2 Darstellung mit absätzen zu speichern.
Gruss.