Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 07-19-2019, 01:18 PM   #1
duke217
Newly Registered User
 
Join Date: Jan 2018
Location: Bratislava, SR
Posts: 13
Thanks: 8
Thanked 1 Time in 1 Post
duke217 is on a distinguished road
displaying data from an xml file on a form

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?

duke217 is offline   Reply With Quote
Old 07-19-2019, 02:13 PM   #2
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,498
Thanks: 58
Thanked 1,420 Times in 1,401 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: displaying data from an xml file on a form

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...
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
The Following User Says Thank You to theDBguy For This Useful Post:
duke217 (08-21-2019)
Old 07-19-2019, 02:19 PM   #3
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 11,262
Thanks: 115
Thanked 3,079 Times in 2,797 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: displaying data from an xml file on a form

Research using the Split function.
As a first step, see https://www.techonthenet.com/access/...ring/split.php
Use raw_text> as your delimiter

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Colin (Mendip Data Systems)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Common sense and a sense of humour are the same thing, moving at different speeds. (Clive James - RIP)
isladogs is offline   Reply With Quote
Old 07-19-2019, 08:25 PM   #4
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,569
Thanks: 68
Thanked 2,745 Times in 2,630 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: displaying data from an xml file on a form

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
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
The Following User Says Thank You to arnelgp For This Useful Post:
duke217 (08-21-2019)
Old 07-20-2019, 01:31 AM   #5
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,518
Thanks: 440
Thanked 841 Times in 812 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: displaying data from an xml file on a form

Just to throw another option in there, you can use csv format as well?

https://www.aviationweather.gov/adds...ionString=EGLL

__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
The Following User Says Thank You to Gasman For This Useful Post:
duke217 (08-21-2019)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying flat file data in a specific hierarchical format in XL Rank Am Modules & VBA 2 03-02-2010 06:09 PM
Form data not displaying Naia Forms 9 12-05-2007 01:44 PM
Form not displaying data tikkat3 Forms 8 04-16-2007 06:27 AM
Displaying data on sub-form DavidRS Forms 1 04-15-2007 10:02 AM
Displaying File information on a Form baresi Forms 0 07-23-2001 01:43 PM




All times are GMT -8. The time now is 11:14 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World