' Il seguente frammento di codice fornisce un esempio di come sia possibile acquisire informazioni da un ' un servizio esterno di rilevazione dati tramite la chiamata ad un WebService utilizzando una URL che restituisce una stringa XML. ' Nella fattispecie, viene utilizzato il Web Service messo a disposizione dal sistema di monitoraggio dei ' pannelli fotovoltaici SolarEdge ) ' L'output è il seguente: ' <series> ' <timeUnit>HOUR</timeUnit> ' <unit>Wh</unit> ' <measuredBy>INVERTER</measuredBy> ' <values> ' <dateValue> ' <date>2017-05-08 00:00:00</date> ' <value>0.0</value> ' </dateValue> ' .... ' </values> ' </series> ' I dati vengono recuperati su base giornaliera (per il giorno corrente) e memorizzati in una griglia Dim d as string=ltrim(str(Today.Year))+"-"+ltrim(str(Today.Month))+"-"+ltrim(str(Today.Day)) Dim url As String = "https://monitoringapi.solaredge.com/site/349661/energy.xml?timeUnit=HOUR&endDate="+d+"&startDate="+d+"&api_key=KDZ46QJYX2HQPIVPJY7KX3R9HA7UENRA" Dim webClient As New System.Net.WebClient Dim result As String = webClient.DownloadString(Url) ' Recupero della risposta e parse dell'XML Dim response = System.XML.Linq.XElement.Parse(result) for each el as System.XML.Linq.Xelement in response.LastNode.Nodes ' Il LastNode è "Values", e ne estrae tutti i nodi ' Il quarto nodo è quello dei Values Dim Data As String Dim Valore as String Data=Ctype(el.FirstNode,System.Xml.Linq.Xelement).Value Valore=Ctype(el.LastNode,System.Xml.Linq.Xelement).Value if Valore<>"null" form.findcontrol("Grid1").MoveFirst() if not form.findcontrol("Grid1").LocateRow("CUSTOM1='"+Data+"'") form.findcontrol("Grid1").AddRow() form.findcontrol("Grid1").AssignField("CUSTOM1",Data) End If form.findcontrol("Grid1").AssignField("NUMBER1",val(Valore)) form.findcontrol("Grid1").SaveRow() End If next form.findcontrol("Grid1").Refresh() form.findcontrol("Grid1").MoveLast()