all-sensors.xml

Moderator: Mattk

Post Reply
Stebi
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: Mon Jul 12, 2010 7:47 pm
Location: Basel, Switzerland
Contact:

all-sensors.xml

Post 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
Stebi
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: Mon Jul 12, 2010 7:47 pm
Location: Basel, Switzerland
Contact:

Re: all-sensors.xml

Post 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
User avatar
benz
Junior Boarder
Junior Boarder
Posts: 25
Joined: Thu May 06, 2010 1:55 pm
Location: CH
Contact:

Re: all-sensors.xml

Post by benz »

Vielen Dank für diesen Hinweis, Thomas!

Gruss benz
ZebraWetter
Junior Boarder
Junior Boarder
Posts: 22
Joined: Sun Aug 14, 2011 11:44 am
Location: Duisburg/northrhine-westfalia/germany/earth/sol system

Re: all-sensors.xml

Post 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
Post Reply