Page 1 of 1
Read XML from URL
Posted: Sat Feb 22, 2020 10:24 pm
by JackWebb
New to XML and so far it seems far more complex than it needs to be. But I'm betting it's really easy and I'm just missing some information. I am attempting to read an XML from a URL
https://api.met.no/weatherapi/locationf ... 0&lon=9.58
I'm not looking to use the entire file and all it's data, I am simply looking to get the temperature and current weather conditions such as rain etc.
And here is the documentation
https://api.met.no/weatherapi/locationf ... umentation
I have no idea what I'm doing, the docs and forum are light on examples.
Thank you in advance!
Jack

Re: Read XML from URL
Posted: Tue Feb 25, 2020 9:47 am
by poshu
And what is the problem? Where does it fail?
Let me get my crystal ball... It says
CORS.
Re: Read XML from URL
Posted: Thu Feb 27, 2020 5:00 am
by JackWebb
poshu wrote:And what is the problem? Where does it fail?
Let me get my crystal ball... It says
CORS.
And if I knew that, then I wouldn't need to ask the question now would I? What does your crystal ball say about that?
Re: Read XML from URL
Posted: Sun Mar 01, 2020 9:25 pm
by Peter
@JackWebb: Did you solve your problem?
Greetings ... Peter
Re: Read XML from URL
Posted: Mon Mar 02, 2020 8:09 am
by plouf
where exaclty have you failed ?
have you actually manage to read the file ?
are you aware that you cannon read files from diffirent domain ?
i.e. if you script runs under
https://api.met.no server domain
Re: Read XML from URL
Posted: Fri Mar 13, 2020 2:34 am
by JackWebb
Peter wrote:@JackWebb: Did you solve your problem?
Greetings ... Peter
Thank you Peter for your reply. I have no time to code anymore, and my health dictates how many hours I can spend sitting down unfortunately. My problem is that I simply do not know how to use this library. I can load the file successfully it seems, but then what? So for now I am just using a scraping method until I have some time to figure this out.
plouf wrote:where exaclty have you failed ?
I don't know that it failed, I don't think it has. This is the code I was using to experiment with the XML library. Not much I know but I didn't get very far.
Code: Select all
Enumeration
#XML
EndEnumeration
Procedure.s XMLStatusString(StatusCode)
Protected Result$
Select StatusCode
Case #PB_XML_Success
Result$ = "no error"
EndSelect
ProcedureReturn Result$
EndProcedure
FileName.s = "https://api.met.no/weatherapi/locationforecast/1.9/?lat=60.10&lon=9.58;"
If LoadXML(#XML, FileName$)
Debug "LoadXML = " + "loaded"
StatusCode = XMLStatus(#XML)
Debug "XMLStatusString = " + XMLStatusString(StatusCode)
If IsXML(#XML) <> 0 And StatusCode = #PB_XML_Success
ParseXML(#XML, FileName$)
encoding = GetXMLEncoding(#XML)
Select encoding
Case #PB_Ascii : Debug "Ascii"
Case #PB_Unicode : Debug "UTF16"
Case #PB_UTF8 : Debug "UTF8"
EndSelect
Debug "Encoding = " + encoding
Debug "ExamineXMLAttributes = " + ExamineXMLAttributes(#PB_XML_Normal)
Debug "IsXML = " + IsXML(#XML)
Debug "StatusCheck = " + GetXMLNodeName(MainXMLNode(#XML))
Debug "GetXMLNodeText = " + GetXMLNodeText(#PB_XML_Normal)
Debug "RootXMLNode = " + RootXMLNode(#XML)
Debug "ResolveXMLNodeName = " + ResolveXMLNodeName(#PB_XML_Normal)
Debug "ResolveXMLAttributeName = " + ResolveXMLAttributeName(#PB_XML_Normal, "forecast")
EndIf
EndIf
Re: Read XML from URL
Posted: Sun Mar 15, 2020 11:31 am
by plouf
never bother with lib but i know that you canot access anything in a different domain tha the one you run to
i.e. you script MUST run in api.met.no server
in ADDITION as manual says you MUST bind a procedure in loading
the following example starts to work if you save your XML to a local file in the same folder/server you run this script
Code: Select all
Enumeration
#XML
EndEnumeration
Procedure.s XMLStatusString(StatusCode)
Protected Result$
Select StatusCode
Case #PB_XML_Success
Result$ = "no error"
Case #PB_XML_Error
result$= "error loading"
EndSelect
ProcedureReturn Result$
EndProcedure
FileName$ = "https://api.met.no/weatherapi/locationforecast/1.9/?lat=60.10&lon=9.58;"
filename$ = "api.met.no.xml"
Procedure Loading()
Debug "LoadXML = " + "loaded"
StatusCode = XMLStatus(#XML)
Debug "XMLStatusString = " + XMLStatusString(StatusCode)
If IsXML(#XML) <> 0 And StatusCode = #PB_XML_Success
; ParseXML(#XML, FileName$)
encoding = GetXMLEncoding(#XML)
Select encoding
Case #PB_Ascii : Debug "Ascii"
Case #PB_Unicode : Debug "UTF16"
Case #PB_UTF8 : Debug "UTF8"
EndSelect
Debug "Encoding = " + encoding
Debug "ExamineXMLAttributes = " + ExamineXMLAttributes(#PB_XML_Normal)
Debug "IsXML = " + IsXML(#XML)
Debug "StatusCheck = " + GetXMLNodeName(MainXMLNode(#XML))
Debug "GetXMLNodeText = " + GetXMLNodeText(#PB_XML_Normal)
Debug "RootXMLNode = " + RootXMLNode(#XML)
Debug "ResolveXMLNodeName = " + ResolveXMLNodeName(#PB_XML_Normal)
Debug "ResolveXMLAttributeName = " + ResolveXMLAttributeName(#PB_XML_Normal, "forecast")
EndIf
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
;BindEvent(#PB_Event_LoadingError, @LoadingError())
LoadXML(#XML, FileName$)