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
Read XML from URL
Read XML from URL
Simplicity is the ultimate sophistication. ~ Leonardo Da Vinci
Re: Read XML from URL
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?poshu wrote:And what is the problem? Where does it fail?
Let me get my crystal ball... It says CORS.
Simplicity is the ultimate sophistication. ~ Leonardo Da Vinci
Re: Read XML from URL
@JackWebb: Did you solve your problem?
Greetings ... Peter
Greetings ... Peter
Re: Read XML from URL
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
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
Christos
Re: Read XML from URL
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.Peter wrote:@JackWebb: Did you solve your problem?
Greetings ... Peter
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.plouf wrote:where exaclty have you failed ?
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
Simplicity is the ultimate sophistication. ~ Leonardo Da Vinci
Re: Read XML from URL
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
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$)
Christos