Autor Zpráva
Tomast
Profil
Našel jsem PHP xml children, ale vůbec z toho nejsem moudrej. Podařilo se mi vypsat text třeba z <title>Bla Bla</title>, ale nemůžu přijít na to, jak dostat z následujícho kódu chill, speed, atd...
XML:
<?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>
<yweather:wind chill="30"   direction="210"   speed="8.05" />
<yweather:units temperature="C" distance="km" pressure="mb" speed="km/h"/>
</channel>
</rss>

PHP:
<?
$feedURL = 'soubor.xml'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$feedURL); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
$result = curl_exec($ch);
$xml = simplexml_load_string($result); 
$channel=stripslashes($xml->channel->item); ?>

Poradí nějaký XML odoborník? Díky.
DJ Miky
Profil
Ke jmenným prostorům se dostaneš takto:
$namespaces = $channel->getNameSpaces(true);
$yweather = $channel->children($namespaces['yweather']);
// pak se dostaneš k $yweather->wind a $yweather->units


K atributům (chill, direction atd.) se dostaneš pomocí metody attributes(), např.:
echo $yweather->wind->attributes()->chill;
echo $yweather->wind->attributes()->direction;

Vaše odpověď


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0