Page 1 of 1

all-sensors.xml

Posted: Sun Sep 25, 2011 5:10 pm
by Stebi
I upgraded from version 4.6t to 4.8a.
From then on I got problems in viewing XML-data: Now with "http://192.xxxxx/meteograph.cgi?text=allxml" I can't open the xml-data any more. I get the error message "XML-Verarbeitungsfehler: nicht wohlgeformt ....". I wrote a script to read out this file with simplexml-load. There, I also get the error message mentioned above: The problem are the german "Umlaute". How can I fix my script to read the new XML-format in Meteohub Version 4.8a?

Here the script:

<html>
<head>
<meta http-equiv='Content-Language' encoding='utf-8' content='de-ch'>
<title>Wetterstation beim Tinguely Museum, Basel, Bergalingerstrasse, Schweiz</title>
</head>
<body>
<?php
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://meteo.square7.ch/all-sensors.xml');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($content);
} else {
$filename = 'http://meteo.square7.ch/all-sensors.xml';
$xml = simplexml_load_file($filename);
}
echo 'Auslesen des Files all-sensors.xml';
for ($k=0, $to=count($xml->data); $k<$to; ++$k)
{
echo '<br />', '<br />';
for ($m=0, $sensorzahl=count($xml->data[$k]->item); $m<$sensorzahl; ++$m)
{
$sensor = $xml->data[$k]->item[$m][sensor];
$cat = $xml->data[$k]->item[$m][cat];
$unit = $xml->data[$k]->item[$m][unit];
echo $xml->data[$k][timeframe], ' -- ' .$k, ' - ' .$m, ' -- ' .$sensor, ' // ' .$cat, ' // ' .$unit, ' // ';
echo $xml->data[$k]->item[$m], '<br />';
}
}
?>
</body>
</html>

Greetings from Basel

Thomas

Re: all-sensors.xml

Posted: Thu Oct 06, 2011 11:19 pm
by Stebi
Hi
I solved the problem. In the XML-File all-sensors.xml the first line should be <?xml version="1.0" encoding="ISO-8859-1" ?>. With this added line, the script above works. Therefore I entered the following code in my sript:

$sourceA = fopen('header.txt', 'rb') or die('!fopen A');
$sourceB = fopen('all-sensors.xml', 'rb') or die('!fopen B');
$target = fopen('all-sensmod.xml', 'wb') or die('!fopen target');
stream_copy_to_stream($sourceA, $target);
stream_copy_to_stream($sourceB, $target);
fclose($target);
fclose($sourceB);
fclose($sourceA);

In the file "header.txt" there is only one line: <?xml version="1.0" encoding="ISO-8859-1" ?>
Now I can read out the file all-sensmod.xml correctly. I found the code in the php.de forum.

Bye
Thomas

Re: all-sensors.xml

Posted: Fri Oct 07, 2011 8:00 pm
by benz
Vielen Dank für diesen Hinweis, Thomas!

Gruss benz

Re: all-sensors.xml

Posted: Fri Nov 04, 2011 10:27 pm
by ZebraWetter
I had the same problem and solved it this way:

$this->weatherdata = simplexml_load_string(utf8_encode(file_get_contents($xmlpath)));

It reads the "all-sensors.xml" which is transferred with FTP to a server outside of my home network.

Andi