PHP code example of cstuder / parse-hydrodaten

1. Go to this page and download the library: Download cstuder/parse-hydrodaten library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cstuder / parse-hydrodaten example snippets



 = file_get_contents('https://www.hydrodaten.admin.ch/lhg/az/xml/hydroweb.xml');

$data = \cstuder\ParseHydrodaten\DataParser::parse($raw);

var_dump($data);

$data->values = [
  (cstuder\ParseValueholder\Value Object) [
    'timestamp' => 1619841168,
    'location' => '2135',
    'parameter' => 'temperature',
    'value' => 11.1
  ],
...
];


 = file_get_contents('https://www.hydrodaten.admin.ch/lhg/az/xml/hydroweb.xml');

$metadata = \cstuder\ParseHydrodaten\MetadataParser::parse($raw);

var_dump($metadata);


$raw = file_get_contents('https://www.hydrodaten.admin.ch/lhg/az/xml/hydroweb.xml');

$data = \cstuder\ParseHydrodaten\DataParser::parse($raw);


$context = stream_context_create(array (
    'http' => array (
        'header' => 'Authorization: Basic ' . base64_encode("$username:$password")
    )
));

$raw = file_get_contents('https://www.hydrodata.ch/data/xml/hydroweb.xml', $context);

$data = \cstuder\ParseHydrodaten\DataParserPrecise::parse($raw);


$context = stream_context_create(array (
    'http' => array (
        'header' => 'Authorization: Basic ' . base64_encode("$username:$password")
    )
));

$raw = file_get_contents('https://www.hydrodata.ch/data/xml/hydroweb.naqua.xml', $context);

$data = \cstuder\ParseHydrodaten\DataParserPrecise::parse($raw);


$raw = file_get_contents('SMS.xml');

$data = \cstuder\ParseHydrodaten\LegacyDataParser::parse($raw);