displaying data from an xml file on a form (1 Viewer)

duke217

Registered User.
Local time
Today, 23:49
Joined
Jan 23, 2018
Messages
17
Hi all,

I am trying to display data from an xml file that I can get from the web.

Here's how it works:

If I call this URL in a browser:
Code:
https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3&mostRecent=true&stationString=EGLL
the website returns an XML page that looks like ths:

Code:
<response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" version="1.2" xsi:noNamespaceSchemaLocation="http://aviationweather.gov/adds/schema/metar1_2.xsd">
<request_index>36589223</request_index>
<data_source name="metars"/>
<request type="retrieve"/>
<errors/>
<warnings/>
<time_taken_ms>6</time_taken_ms>
<data num_results="1">
<METAR>
<raw_text>
EGLL 192050Z AUTO 21009KT 9999 -RA FEW011 BKN018 BKN024 18/17 Q1009 TEMPO RA BKN009
</raw_text>
<station_id>EGLL</station_id>
<observation_time>2019-07-19T20:50:00Z</observation_time>
<latitude>51.48</latitude>
<longitude>-0.45</longitude>
<temp_c>18.0</temp_c>
<dewpoint_c>17.0</dewpoint_c>
<wind_dir_degrees>210</wind_dir_degrees>
<wind_speed_kt>9</wind_speed_kt>
<visibility_statute_mi>6.21</visibility_statute_mi>
<altim_in_hg>29.793306</altim_in_hg>
<quality_control_flags>
<auto>TRUE</auto>
</quality_control_flags>
<wx_string>-RA</wx_string>
<sky_condition sky_cover="FEW" cloud_base_ft_agl="1100"/>
<sky_condition sky_cover="BKN" cloud_base_ft_agl="1800"/>
<sky_condition sky_cover="BKN" cloud_base_ft_agl="2400"/>
<flight_category>MVFR</flight_category>
<metar_type>METAR</metar_type>
<elevation_m>24.0</elevation_m>
</METAR>
</data>
</response>

Now, what I have been trying to achieve for quite some time is to display the text between the <raw_text> and </raw_text> tags to be displayed on my form.

Any idea how to do that?:confused:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:49
Joined
Oct 29, 2018
Messages
21,358
Hi. You will have to store the xml in a variable and then parse it using VBA. There should be some sample code available here to do that by doing a quick search

Sent from phone...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:49
Joined
May 7, 2009
Messages
19,169
first read the file content to a variable string.
then find the tag <raw_text> save its position on the string.
next find </raw_text>, save it's position on the string.
then using mid() function extract the string within.
split the string you extracted and put it to your
textbox:
Code:
Dim objFSO As Object 		'Scripting.FileSystemObject
Dim objText As As Object 	'Scripting.TextStream
Dim strContent As String
Dim Pos1 As Integer
Dim Pos2 As Integer
Dim var As Variant

Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set objText = objFSO.OpenTextFile("D:\theXMLFileHere.xml", ForReading)
strContent = objText.ReadAll()
Pos1=Instr(1, strContent, "<raw_text>")
If Pos1 <> 0 Then
	Pos1=Pos1 + Len("<raw_text>")
	Pos2 = Instr(Pos1, strContent, "</raw_text>")
	If Pos2 <> 0 Then
		strContent = Mid(strContent, Pos1, Pos2 - Pos1)
		While Instr(strContent, "  ")
			strContent = Replace(strContent, "  ", " ")
		Wend
		var = Split(strContent, " ")
		[YourTextbox1] = var(0)
		[YourTextbox2] = var(1)
		[YourTextbox3] = var(3)
		...
		...
	End If
End If
Set ObjText=Nothing
Set ObjFSO = Nothing
 

Users who are viewing this thread

Top Bottom