Antworten auf deine Fragen:
Neues Thema erstellen

Antworten zum Thema „.xml in HTML einbinden“

D

DJ Fotoart

Guest

AW: .xml in HTML einbinden

Hallo

Okay, ich hab von PHP leider keine Ahnung, hab deinen Code mal dazugepackt und mir das im Browser angesehen. Dabei kommt dieses raus:

KlarºC
2009-03-31 08:34:15 +0000
Feuchtigkeit: 65%
45
/images/weather/sunny.gif

Wind: N mit 0 km/hºC | Di.ºC
/images/weather/sunny.gif

KlarºC | Mi.ºC
/images/weather/sunny.gif

KlarºC | Do.ºC
/images/weather/sunny.gif

KlarºC | Fr.ºC
0: <?xml version=
1: 1.0
2: ?><xml_api_reply version=
3: 1
4: ><weather module_id=
5: 0
6: tab_id=
7: 0
8: mobile_row=
9: 0
10: mobile_zipped=
11: 1
12: ><forecast_information><city data=
13: Wesel, N Rhine-Westphalia
14: /><postal_code data=
15: Wesel
16: /><latitude_e6 data=
17: /><longitude_e6 data=
18: /><forecast_date data=
19: 2009-03-31
20: /><current_date_time data=
21: 2009-03-31 08:34:15 +0000
22: /><unit_system data=
23: SI
24: /></forecast_information><current_conditions><condition data=
25: Klar
26: /><temp_f data=
27: 45
28: /><temp_c data=
29: 7
30: /><humidity data=
31: Feuchtigkeit: 65%
32: /><icon data=
33: /images/weather/sunny.gif
34: /><wind_condition data=
35: Wind: N mit 0 km/h
36: /></current_conditions><forecast_conditions><day_of_week data=
37: Di.
38: /><low data=
39: 4
40: /><high data=
41: 13
42: /><icon data=
43: /images/weather/sunny.gif
44: /><condition data=
45: Klar
46: /></forecast_conditions><forecast_conditions><day_of_week data=
47: Mi.
48: /><low data=
49: 6
50: /><high data=
51: 14
52: /><icon data=
53: /images/weather/sunny.gif
54: /><condition data=
55: Klar
56: /></forecast_conditions><forecast_conditions><day_of_week data=
57: Do.
58: /><low data=
59: 6
60: /><high data=
61: 16
62: /><icon data=
63: /images/weather/sunny.gif
64: /><condition data=
65: Klar
66: /></forecast_conditions><forecast_conditions><day_of_week data=
67: Fr.
68: /><low data=
69: 9
70: /><high data=
71: 18
72: /><icon data=
73: /images/weather/sunny.gif
74: /><condition data=
75: Klar
76: /></forecast_conditions></weather></xml_api_reply>

Nur anfangen kann ich damit nichts :(


Edit: Gegentest mit einer statischen .php Seite bringt das gleiche Ergebnis, also liegt es schon mal nicht an Joomla.
 
Zuletzt bearbeitet von einem Moderator:

netbandit

Aktives Mitglied

AW: .xml in HTML einbinden

Hallo

Okay, ich hab von PHP leider keine Ahnung, ....

Achso, wusste ich nicht. Also hier mal ein wenig anders:

PHP:
<?php
$catch[0]='forecast_information';
$catch[1]='current_conditions';
$catch[2]='forecast_conditions';
$url = "http://www.google.com/ig/api?weather=Wesel&hl=de";
$file = implode(file($url));
foreach($catch as $k => $v){
        preg_match_all("/<" . $v . ">(.*)<\/" . $v . ">/Uis", $file, $array_infos);
        $infos = $array_infos[1];
        $ct_infos=count($infos);
        if($ct_infos>=1){
           for($i=0;$i<$ct_infos;$i++){
               preg_match_all("/<(.*) data=\"(.*)\"\/>/Uis", $infos[$i], $array_details);
               $detail_keys=$array_details[1];
               $detail_values=$array_details[2];
               $ct_details=count($detail_keys);
               if($ct_details>=1){
                  for($j=0;$j<$ct_details;$j++){
                      $data[ $v . '|' . $detail_keys[$j] . '|' . ($i+1)]=$detail_values[$j];
                  }
               }
           }
        }
}
?>
          <table>
            <tr>
              <td><div style="padding:5px;float:left">
                  <div><b><?php echo $data['current_conditions|condition|1']; ?>&ordm;C</b></div>
                  <div><b><?php echo $data['current_conditions|temp_c|1'];?></b><br />
                    <?php echo $data['current_conditions|wind_condition|1']; ?><br />
                    <?php echo $data['current_conditions|humidity|1']; ?></div>
                </div>
                <div align="center" style="padding:5px;float:left;"><?php echo $data['forecast_conditions|day_of_week|1']; ?><br />
                  <img src="http://www.google.com/<?php echo $data['forecast_conditions|icon|1'];?>" alt="" /><br />
                  <?php echo $data['forecast_conditions|low|1']; ?>&ordm;C | <?php echo $data['forecast_conditions|high|1']; ?>&ordm;C</div>
                <div align="center" style="padding:5px;float:left;"><?php echo $data['forecast_conditions|day_of_week|2']; ?><br />
                  <img src="http://www.google.com/<?php echo $data['forecast_conditions|icon|2'];?>" alt="" /><br />
                  <?php echo $data['forecast_conditions|low|2']; ?>&ordm;C | <?php echo $data['forecast_conditions|high|2']; ?>&ordm;C</div>
                <div align="center" style="padding:5px;float:left;"><?php echo $data['forecast_conditions|day_of_week|3']; ?><br />
                 <img src="http://www.google.com/<?php echo $data['forecast_conditions|icon|3'];?>" alt="" /><br />
                  <?php echo $data['forecast_conditions|low|3']; ?>&ordm;C | <?php echo $data['forecast_conditions|high|3']; ?>&ordm;C</div>
                <div align="center" style="padding:5px;float:left;"><?php echo $data['forecast_conditions|day_of_week|4']; ?><br />
                  <img src="http://www.google.com/<?php echo $data['forecast_conditions|icon|4'];?>" alt="" /><br />
                  <?php echo $data['forecast_conditions|low|4']; ?>&ordm;C | <?php echo $data['forecast_conditions|high|4']; ?>&ordm;C</div>
             </td>
            </tr>
          </table>

Nicht unbedingt optimal, lässt sich bei Änderung aber bestimmt einfacher anpassen, Beispiel


echo $data['current_conditions|wind_condition|1']

entspricht (Auszug aus der xml-Datei)

<current_conditions>
<condition data="Klar" />
<temp_f data="53" />
<temp_c data="11" />
<humidity data="Feuchtigkeit: 40%" />
<icon data="/images/weather/sunny.gif" />
<wind_condition data="Wind: SW mit 0 km/h" />
</current_conditions>
und dann aus current_conditions den ersten Datensatz
 
Zuletzt bearbeitet:
D

DJ Fotoart

Guest

AW: .xml in HTML einbinden

Hi

Na das ist doch schon sehr gut so, es funktioniert zumindest schon mal :)

So schauts aus: Webcam Wesel

Vielen dank dafür.
 

netbandit

Aktives Mitglied

AW: .xml in HTML einbinden

Ups, ich habe condition und temp_c vertauscht
statt
PHP:
<div><b><?php echo $data['current_conditions|condition'][1]; ?>&ordm;C</b></div>
<div><b><?php echo $data['current_conditions|temp_c'][1];?></b><br />

PHP:
<div><b><?php echo $data['current_conditions|temp_c'][1]; ?>&ordm;C</b></div>
<div><b><?php echo $data['current_conditions|condition'][1];?></b><br />
 
D

DJ Fotoart

Guest

AW: .xml in HTML einbinden

Hab ich schon umgeändert und noch einen kleinen Text davor eingefügt :)
 

netbandit

Aktives Mitglied

AW: .xml in HTML einbinden

Hast Du zufällig einen Link zur Hand, wo steht wer und wie die Wetterdaten von Google genutzt werden können? :)
 
D

DJ Fotoart

Guest

AW: .xml in HTML einbinden

Du meinst die rechtliche Seite?
Laut G. ist das kein Problem, denn die bieten die Möglichkeit ja auch für die Toolbar an.



Das Netz sagt wiedersprüchliches zu dem Thema, zum Beispiel hier: Google Wetter-API | Hackthenet-Blog

Ich hab damals G. angeschrieben, aber leider nie eine Antwort erhalten. Und so lange G. sich nicht bei mir beschwert (was sie seit Ewigkeiten nicht getan haben) ist mir das beinahe egal. Zur Not wird es halt entfernt.
 
K

Knut_Wilhelm

Guest

AW: .xml in HTML einbinden

@netbandit

deine Anleitung (Quellcode) ist super, jedoch habe ich das Problem, dass einige xml-Dateien Attribute beinhalten, die sich ändern, jedoch enorm wichtig sein können.

Wie kann man solche interpretieren und ausgeben?

Bsp:

<PHP-Code:>
[dayf] => SimpleXMLElement Object
(
[lsup] => 11/14/09 6:19 PM Local Time
[day] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[d] => 0
[t] => Saturday
[dt] => Nov 14
)

[hi] => N/A
[low] => 8
[sunr] => 7:37 AM
[suns] => 4:42 PM
</PHP-Code:>

Das Ergebnis sollte dann entsprechend so aussehen:

<?php echo $data['dayf|day|0|...|d']; ?>
<?php echo $data['dayf|day|0|...|t']; ?>
<?php echo $data['dayf|day|0|...|dt']; ?>

Ausgabe:
0
Saturday
Nov 14

Besten Dank im Vorraus

Knut
 
Zuletzt bearbeitet von einem Moderator:
Bilder bitte hier hochladen und danach über das Bild-Icon (Direktlink vorher kopieren) platzieren.
Antworten auf deine Fragen:
Neues Thema erstellen

Willkommen auf PSD-Tutorials.de

In unseren Foren vernetzt du dich mit anderen Personen, um dich rund um die Themen Fotografie, Grafik, Gestaltung, Bildbearbeitung und 3D auszutauschen. Außerdem schalten wir für dich regelmäßig kostenlose Inhalte frei. Liebe Grüße senden dir die PSD-Gründer Stefan und Matthias Petri aus Waren an der Müritz. Hier erfährst du mehr über uns.

Stefan und Matthias Petri von PSD-Tutorials.de

Nächster neuer Gratisinhalt

03
Stunden
:
:
25
Minuten
:
:
19
Sekunden

Neueste Themen & Antworten

Flatrate für Tutorials, Assets, Vorlagen

Statistik des Forums

Themen
175.189
Beiträge
2.582.077
Mitglieder
67.259
Neuestes Mitglied
SaschMasch1312
Oben