Warnung: file_put_contents(/home/www/web1/html/php_dev/test.txt) [function.file-put-contents]: failed to open stream: Permission denied in /home/www/web1/html/php_dev/sys/lib.activity.php (Zeile 58)
simplexml_load_file() doppelpunkt Problem [Archiv] - PHP-Scripte PHP-Tutorials PHP-Jobs und vieles mehr
ebiz-webhosting
- Ad -
php-resource




Archiv verlassen und diese Seite im Standarddesign anzeigen :
simplexml_load_file() doppelpunkt Problem


 
Shin Yoshida
28-06-2006, 21:20 
 
Hallo Community,
ich habe wieder einmal ein Problem. Zwar lese ich die XML Wetterdaten von Yahoo aus. Diese Daten werden als XML angeboten. Das XML file sieht so aus:


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
<title>Yahoo! Weather - Akita, JA</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Akita__JA/*
http://xml.weather.yahoo.com/forecast/JAXX0001_f.html</link>
<description>Yahoo! Weather for Akita, JA</description>
<language>en-us</language>
<lastBuildDate>Wed, 28 Jun 2006 12:08 pm PDT</lastBuildDate>

<ttl>60</ttl>
<yweather:location city="Akita" region="" country="JA" />
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph" />
<yweather:astronomy sunrise="4:14 am" sunset="7:12 pm" />
<image>
<title>Yahoo! Weather</title>
<width>142</width>

<height>18</height>
<link>http://weather.yahoo.com/</link>
<url>http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
</image>
<item>
<title>Conditions for Akita, JA</title>
<geo:lat>39.72</geo:lat>

<geo:long>140.1</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Akita__JA/*
http://xml.weather.yahoo.com/forecast/JAXX0001_f.html</link>
<pubDate>Wed, 28 Jun 2006 12:08 pm PDT</pubDate>
<description><![CDATA[
<b>Forecast:</b><BR />
Wed - Sunny. High: 75 Low: 63<br />
Thu - Partly Cloudy. High: 77 Low: 65<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Akita__JA/*
http://xml.weather.yahoo.com/forecast/JAXX0001_f.html">Full Forecast at Yahoo! Weather</a><BR/>
(provided by The Weather Channel)<br/>
]]></description>
<yweather:forecast day="Wed" date="28 Jun 2006" low="63" high="75" text="Sunny" code="32" />
<yweather:forecast day="Thu" date="29 Jun 2006" low="65" high="77" text="Partly Cloudy" code="30" />
<guid isPermaLink="false">JAXX0001_2006_06_28_JST</guid>

</item>
</channel>
</rss>

Dieses XML File lese ich dan mir simplexml_load_file() ein. Mit print_r lasse ich mir dan folgendes ausgeben.


SimpleXMLElement Object
(
[channel] => SimpleXMLElement Object
(
[title] => Yahoo! Weather - Akita, JA
[link] => http://us.rd.yahoo.com/dailynews/rss/weather/Akita__JA/*http://xml.weather.yahoo.com/forecast/JAXX0001_f.html
[description] => Yahoo! Weather for Akita, JA
[language] => en-us
[lastBuildDate] => Wed, 28 Jun 2006 12:07 pm PDT
[ttl] => 60
[image] => SimpleXMLElement Object
(
[title] => Yahoo! Weather
[width] => 142
[height] => 18
[link] => http://weather.yahoo.com/
[url] => http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif
)

[item] => SimpleXMLElement Object
(
[title] => Conditions for Akita, JA
[link] => http://us.rd.yahoo.com/dailynews/rss/weather/Akita__JA/*http://xml.weather.yahoo.com/forecast/JAXX0001_f.html
[pubDate] => Wed, 28 Jun 2006 12:07 pm PDT
[description] => SimpleXMLElement Object
(
)

[guid] => JAXX0001_2006_06_28_JST
)

)

)


Hier werden nun die <yweather:wathever> nicht mehr angezeigt was meiner Meinung nach auch ganz normal ist. Nur kann ich auch mit attributes nicht darauf zugreifen. Ich frage mich nun wie komme ich an diese werte da diese eigentlich die Huptinformationen dieses Dokumentes ausgeben.

Meine idee war :


<?php
$url = 'http://xml.weather.yahoo.com/forecastrss?p=JAXX0001&u=f';
$xml = simplexml_load_file($url);

/* Hier haben wir aber einen Syntaxfehler */
foreach($xml->channel->yweather:location->attributes() as ... )
{
// output
}

/* Auch keine Funktion gibt Call to a member function attributes() on a non-object in ... */
foreach($xml->channel['yweather:location']->attributes() as ... )
{
// output
}

?>



Kennt jemand das Problem? Kann mir wer Helfen.
Danke schon mal

gruss
shin y.

 
Nezzar
29-06-2006, 09:27 
 
Ich bin mir nicht ganz sicher, ob es das ist, was du brauchst, aber schau dir mal das hier an: http://de3.php.net/manual/en/function.simplexml-element-registerxpathnamespace.php

- -

Alle Zeitangaben in WEZ +2. Es ist jetzt 18:03 Uhr.