I have used Node Red for some time now on my RPi and I am very happy with it!
Now I have given myself a new challenge: To grab some specific data from a xml-file in Node Red.
I have a very large xml-file (60K+ lines) containing UV-radiation data downloaded from a weather service (a small part of it is given below). The file contains radiation forecasts for many locations given as longitude and latitude in short notation. I tried to use the debug window to grab the path to the data of interest, but it seems that each time I download an updated version of the xml, the path has changed. So I get data from another location each time the xml is updated. Not very useful…
So now I believe I need to use some jsonata query to solve this. But I have very little experience with that. Played around with the try.josonata.org. This have me some new insight, but since the location elements are named latitude and longitude with a hyphen in front ('-latitude' and '-longitude') it is not that easy to work with.
If I remove the hyphens from the jsonata-file converted from xml, then this is a working query:
I have used Node Red for some time now on my RPi and I am very happy with it.
Now I have given myself a new challenge: To get xml-data to work inside Node Red.
I have a large xml-file (60K+ lines) containing UV-radiation data downloaded from a weather service. The file contains radiation forecasts for many locations given as longitude and latitude in short notation. I tried to use the debug window to grab the path to the data of interest, but it seems that each time I download an updated version of the xml, the path has changed. So I get data from another location each time the xml is updated. Not very useful…
So now I believe I need to use some jsonata query to solve this. But I have very little experience with that. Played around with my data at try.josonata.org. This have given me some new insight, but since the location elements are named latitude and longitude with a hyphen in front ('-latitude' and '-longitude') it is not that easy to work with, it seems.
If I remove the hyphens from the jsonata-file converted from xml, this is a working query:
weatherdata.product.time.location[longitude='11.00' and latitude='56.75'].iv.uvi_forecast
(this is not my actual location, so please do not fire a missile…)
But since I have to deal with the hyphens, I also tried this:
weatherdata.product.time.location['longitude=11.00' and 'latitude=56.75'].iv.uvi_forecast
but that returns all uvi_forecast values in the dataset, not only for that given location.
In Node Red I use the http node to get an updated file and save that to disk (daily buffer). Then I use the xml node to convert that saved xml file to json format. This seems to work 100%.
The step I am struggling with is to grab the exact data from a specific location from that json so I can use it for mqtt, MySQL or whatever I find useful. But now I am stuck with the part getting the exact data from json …
Please help me solve this.
Thanks in advance.
Here is an example of the json data converted from xml:
{
"weatherdata": {
"-xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"product": {
"-class": "uvforecast",
"time": {
"-to": "2019-07-09T12:00:00Z",
"-from": "2019-07-09T12:00:00Z",
"location": [
{
"-altitude": "0.00",
"longitude": "11.00",
"latitude": "56.75",
"uv": {
"uvi_clear": {
"-value": "5.21",
"-unit": "uv-index"
},
"uvi_partly_cloudy": {
"-value": "4.43",
"-unit": "uv-index"
},
"uvi_cloudy": {
"-value": "1.35",
"-unit": "uv-index"
},
"uvi_forecast": {
"-value": "5.18",
"-unit": "uv-index"
},
"ozon": {
"-value": "7.755525e-03",
"-unit": "kg/m^-2"
},
"snowcover": {
"-value": "0.00",
"-unit": "percentage"
},
"cloud_cover": {
"-value": "1.00",
"-unit": "parts of 8"
},
"albedo": {
"-value": "0.05",
"-unit": "percentage"
},
"solar_zenith": {
"-value": "34.41",
"-unit": "angle"
}
}
},
{
"-altitude": "0.19",
"longitude": "29.00",
"latitude": "64.00",
"uv": {
"uvi_clear": {
"-value": "4.51",
"-unit": "uv-index"
},
"uvi_partly_cloudy": {
"-value": "3.83",
"-unit": "uv-index"
},
"uvi_cloudy": {
"-value": "1.17",
"-unit": "uv-index"
},
"uvi_forecast": {
"-value": "1.17",
"-unit": "uv-index"
},
"ozon": {
"-value": "7.077940e-03",
"-unit": "kg/m^-2"
},
"snowcover": {
"-value": "0.00",
"-unit": "percentage"
},
"cloud_cover": {
"-value": "8.00",
"-unit": "parts of 8"
},
"albedo": {
"-value": "0.05",
"-unit": "percentage"
},
"solar_zenith": {
"-value": "41.66",
"-unit": "angle"
}
}
},
{
"-altitude": "0.32",
"longitude": "22.25",
"latitude": "67.75",
"uv": {
"uvi_clear": {
"-value": "4.10",
"-unit": "uv-index"
},
"uvi_partly_cloudy": {
"-value": "3.49",
"-unit": "uv-index"
},
"uvi_cloudy": {
"-value": "1.07",
"-unit": "uv-index"
},
"uvi_forecast": {
"-value": "3.07",
"-unit": "uv-index"
},
"ozon": {
"-value": "6.717272e-03",
"-unit": "kg/m^-2"
},
"snowcover": {
"-value": "0.00",
"-unit": "percentage"
},
"cloud_cover": {
"-value": "5.00",
"-unit": "parts of 8"
},
"albedo": {
"-value": "0.05",
"-unit": "percentage"
},
"solar_zenith": {
"-value": "45.40",
"-unit": "angle"
}
}
}
]
}
}
}
}