[HELP] xml parsing how to read some nodes

General discussions related to php

Moderators: macek, egami, gesf

colaiutavinnie
New php-forum User
New php-forum User
Posts: 1
Joined: Fri Feb 21, 2014 12:17 am

[HELP] xml parsing how to read some nodes

Postby colaiutavinnie » Fri Feb 21, 2014 1:49 am

Hello Guys,
I'm very noob with php and this is my first try and script.
The wheater service of my province has an xml and I want to read some nodes and informations from it.

this is my script:

Code: Select all

<?php
strtotime( $xsd_formatted_date );
$xml = simplexml_load_file("https://username:password@wetter.ws.siag.it/Weather_V1.svc/web/getLastProvBulletin?lang=it");
$today = $xml->today;
$stationData = $xml->stationData;
$symbol = $xml->symbol;
$temperature = $xml->temperature;
foreach ($today as $dati){
 
    echo "Condizioni: ".$dati->conditions."<br>\n";
    echo "Data: ".$dati->date."<br>\n";
    echo "<img src=".$dati->imageURL."<br>\n";
    echo "<hr>\n";

}
?>


and this is the xml file:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<provBulletin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><date>2014-02-21T00:00:00</date><dayForecast><date>2014-02-22T00:00:00</date><reliability>70</reliability><symbol><code>c</code><description>Nuvoloso</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_3.png</imageURL></symbol><tempMax><max>12</max><min>1</min></tempMax><tempMin><max>3</max><min>-1</min></tempMin></dayForecast><dayForecast><date>2014-02-23T00:00:00</date><reliability>80</reliability><symbol><code>a</code><description>Sereno</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_1.png</imageURL></symbol><tempMax><max>11</max><min>1</min></tempMax><tempMin><max>-1</max><min>-6</min></tempMin></dayForecast><dayForecast><date>2014-02-24T00:00:00</date><reliability>80</reliability><symbol><code>a</code><description>Sereno</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_1.png</imageURL></symbol><tempMax><max>10</max><min>1</min></tempMax><tempMin><max>-2</max><min>-8</min></tempMin></dayForecast><dayForecast><date>2014-02-25T00:00:00</date><reliability>60</reliability><symbol><code>d</code><description>Molto nuvoloso</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_4.png</imageURL></symbol><tempMax><max>9</max><min>-1</min></tempMax><tempMin><max>0</max><min>-5</min></tempMin></dayForecast><dayForecast><date>2014-02-26T00:00:00</date><tempMax/><tempMin/></dayForecast><evolution>Sabato le precipitazioni si esauriranno e da ovest nel pomeriggio arriveranno le schiarite. In Val Venosta e Alta Valle Isarco spirerà il Föhn da Nord. Domenica e lunedì dominerà il sole mentre martedì le nubi aumenteranno nuovamente.</evolution><evolutionTitle>Miglioramento nel fine settimana</evolutionTitle><hour>07:30</hour><Id>21947</Id><mountainToday><conditions>Da ovest si avvicina un fronte freddo che attraverserà l'Alto Adige nella notte.</conditions><date>2014-02-21T00:00:00</date><imageURL>http://www.provinz.bz.it/wetter/graphics.asp?type=mountainmap0&amp;ID=21947&amp;lang=it&amp;color=1</imageURL><moonSet>09:58</moonSet><north><code>c</code><description>Nuvoloso</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_3.png</imageURL></north><reliability>80</reliability><snowlimit>600-1200</snowlimit><south><code>c</code><description>Nuvoloso</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_3.png</imageURL></south><sunRise>07:09</sunRise><sunSet>17:50</sunSet><temp1000>5</temp1000><temp2000>-1</temp2000><temp3000>-7</temp3000><temp4000>-14</temp4000><title>Nel pomeriggio le prime nevicate</title><weather>In giornata le nubi si alterneranno a tratti soleggiati. Verso sera ad iniziare dal Resia ci saranno delle nevicate che in nottata si estenderanno a gran parte del territorio. Apporti previsti di neve fresca tra 10 e 20 cm.</weather><wind><code>F1</code><description>debole da sudovest</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wind/wind_1_sw.png</imageURL></wind><zerolimit>1700</zerolimit></mountainToday><today><conditions>Da ovest si avvicina un fronte freddo che attraverserà l'Alto Adige nella notte.</conditions><date>2014-02-21T00:00:00</date><imageURL>http://www.provinz.bz.it/wetter/graphics.asp?type=meteomap0&amp;ID=21947&amp;lang=it&amp;color=1</imageURL><stationData><Id>1</Id><symbol><code>c</code><description>Nuvoloso</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_3.png</imageURL></symbol><temperature><max>8</max><min>0</min></temperature></stationData><stationData><Id>2</Id><symbol><code>c</code><description>Nuvoloso</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_3.png</imageURL></symbol><temperature><max>10</max><min>2</min></temperature></stationData><stationData><Id>3</Id><symbol><code>c</code><description>Nuvoloso</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_3.png</imageURL></symbol><temperature><max>10</max><min>2</min></temperature></stationData><stationData><Id>4</Id><symbol><code>c</code><description>Nuvoloso</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_3.png</imageURL></symbol><temperature><max>6</max><min>-1</min></temperature></stationData><stationData><Id>5</Id><symbol><code>c</code><description>Nuvoloso</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_3.png</imageURL></symbol><temperature><max>8</max><min>2</min></temperature></stationData><stationData><Id>6</Id><symbol><code>c</code><description>Nuvoloso</description><imageURL>http://www.provinz.bz.it/wetter/imgsource/wetter/icon_3.png</imageURL></symbol><temperature><max>6</max><min>-1</min></temperature></stationData><temperatures>Valori massimi tra 2° e 11°.</temperatures><title>Nubi in aumento</title><weather>Localmente, come in Val Pusteria, ci saranno formazioni di nubi basse, altrove il tempo sarà ancora buono. Nel pomeriggio le nubi aumenteranno e verso sera ci saranno le prime nevicate nella zona del Passo Resia. Nella notte le precipitazioni assumeranno carattere diffuso. Limite della neve in calo da 1200 fino a 600 m.</weather></today></provBulletin>


i want to read all the informations from "today" node where the stationData Id = 3

This is the mapped xml
Image

XML link -> http://www.robertoandreasi.com/getLastProvBulletin.xml

thank you :)
Sorry but i'm a newbye and this is my first try to use php and xml

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: [HELP] xml parsing how to read some nodes

Postby seandisanti » Thu Feb 27, 2014 10:51 am

Here's a short video of using simplexml from the creator of jream.com http://www.youtube.com/watch?v=Nke7SmhDh-M He used to have them all listed on his site, but now they're all on his youtube channel.


Return to “PHP General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron