I want to download river runoff (.xml) files from a ChartServer online and create a .txt file with the information by running a .sh script. But I'm having difficulty in getting the data out in the correct format.
I have added part of my script in hopes that someone can point me in the right direction on how to get this to work.
url="http://h-web01.nve.no/ChartServer/ShowData.aspx?req=getchart&ver=1.0&time=-10;0&vfmt=xml&chd=ds=htsr,rt=1,da=18,id=700.2.2.1001.0"
xmllint --xpath '//SeriesData/Serie/Point/Value' ${url} | tr '</Value>' '\n' | grep -v '^$' > value_2.2.txt
xmllint --xpath '//SeriesData/Serie/Point/DateTime' ${url} | tr '</DateTime>' '\n' | grep -v '^$' > datetime.txt
if [ -s datetime.txt ]; then
while true; do
read month || break
read day || break
read year || break
read hour || break
echo ${year} ${month} ${day} >> date_2.2.txt
done < datetime.txt
# Put the date and runoff file together
while read Q <&3 && read y m d <&4; do
echo ${y} ${m} ${d} ${Q} >> runoff_2.2.txt
done 3<value_${fra}.${til}.txt 4<date_2.2.txt
I want the .txt file to contain:
yyyy month day value
However my code only gives the value
for every other "DateTime":
yyyy hh:mm:ss month day value
yyyy hh:mm:ss month day
yyyy hh:mm:ss month day value
...
Source data
<?xml version="1.0" encoding="utf-8"?>
<SeriesData>
<Serie>
<Legend>Glomma med kystområder (700.2.2), Vannføring (m³/s)</Legend>
<Point>
<DateTime>03/07/2020 12:00:00</DateTime>
<Value>673.2365</Value>
</Point>
<Point>
<DateTime>03/08/2020 12:00:00</DateTime>
<Value>695.2465</Value>
</Point>
<Point>
<DateTime>03/09/2020 12:00:00</DateTime>
<Value>786.8168</Value>
</Point>
<Point>
<DateTime>03/10/2020 12:00:00</DateTime>
<Value>766.8459</Value>
</Point>
<Point>
<DateTime>03/11/2020 12:00:00</DateTime>
<Value>758.2921</Value>
</Point>
<!-- ...more data... -->
<Point>
<DateTime>03/16/2020 12:00:00</DateTime>
<Value>702.8088</Value>
</Point>
<Statistics/>
</Serie>
</SeriesData>