• 0

VB6 Reading XML from website


Question

I'm totally new to Visual Basic 6 so please forgive me if this is a dumb question that has an easy answer. I've searched but I can't find an easy solution that someone like me would understand.

Here is what I would like to do. I want to access a website using my program and read in one of 2 XML file. After reading them, I want it add the values to a variable.

The first XML may be on a URL like: http://www.example.com/version.xml

The XML will look exactly like:

<version>
	<number>3.1.5</number>
</version>

The second XML may be on a URL like: http://www.example.com/news.xml

The XML will look exactly like:

<message>
	<id>786</id>
	<name>Tony Lock</name>
	<subject>Hello World</subject>
	<forum>General</forum>
</message>

I don't have any idea how to connect to a website using VB or how to cycle thought an XML and parse the variables I want. So ideally, the following variables would be populated with the values from the XML:

+-----------+---------------+
|  VB VAR   |  VALUES	   |
+===========+===============+
|  Version  |  3.1.5		|
+-----------+---------------+
|  ID	   |  786		  |
+-----------+---------------+
|  Name	 |  Tony Lock	|
+-----------+---------------+
|  Subject  |  Hello World  |
+-----------+---------------+
|  Forum	|  General	  |
+-----------+---------------+

Thank you so much for your help.

Link to comment
https://www.neowin.net/forum/topic/773202-vb6-reading-xml-from-website/
Share on other sites

13 answers to this question

Recommended Posts

  • 0

I am new to VB and I was given a copy of VB6. I did not even know about VB.net. Where can I download visual basic .net from?

None the less, can you still help me with the code? I am too new at this to even know where to begin.

Edited by TonyLock
  • 0

i concur, your task will be a lot leasier with .net (c# or vb), so if you don't need to use vb6 or are not that far along in your development to mind switching go download it and give it a shot..

i will knock up an example for you when i get into work tomorrow :)

good luck.

  • 0
  TonyLock said:
I am new to VB and I was given a copy of VB6. I did not even know about VB.net. Where can I download visual basic .net from?

None the less, can you still help me with the code? I am too new at this to even know where to begin.

I'll be glad to try. I only suggested updating VB because it'll take me ages to remember/reference VB6 and MS-XML. :)

All the express versions of Visual Studio can be found at http://msdn.microsoft.com/express

(Don't forget the documentation library at the bottom of the page.)

  • 0

Thank you but I have uninstaller VB.net, it was jus way too bloated and none of my old VB6 files our load.

Anyway, what's wrong with spoon feeding? :-P

I've always thought that one of the best ways to learn is not just to experiment (in my case, just stabbing in the dark) but to learn from experienced people, like you folk. And as for using Google, well what do you think I've been doing all weekend, without success?

  • 0
  TonyLock said:
I'm totally new to Visual Basic 6 ...
  TonyLock said:
... and none of my old VB6 files our load.

Surely there can't be that many of them.. :p

But seriously, handling HTTP Requests, XML, and even encryption (from your other thread) is much easier in .Net.

  • 0

There should be a converter to import VB6 into VB .NET. Is it not included anymore?

If you're still wanting to try .NET, here is the first step: requesting the file from the web server. (I'm using the World of Warcraft realm server status as an example because it's a known Url.)

Module XmlModule
	Dim requestUrl As String = "http://www.worldofwarcraft.com/realmstatus/status.xml"

	Sub Main()
		Dim xmlData As String = GetXmlFromUri(requestUrl)
		Console.WriteLine("WoW realm status data:")
		Console.WriteLine()
		Console.WriteLine(xmlData)
		Console.WriteLine()
		Console.Write("Pressr to exit.")
		Console.ReadLine()
	End Sub

	Function GetXmlFromUri(ByVal uri As String) As String
		' This creates a System.Net.WebRequest class that will 
		' get the XML file from the web server
		Dim req As Net.HttpWebRequest = Net.WebRequest.Create(requestUrl)

		' This creates a System.Net.WebResponse class by sending the
		' request and receiving the data.
		Dim resp As Net.HttpWebResponse = req.GetResponse()

		' This creates a System.IO.StreamReader class that will read
		' the xml data from the HttpWebResponse class.
		Dim reader As IO.StreamReader = New IO.StreamReader(resp.GetResponseStream())

		' Read the entire text stream from the response via 
		' the StreamReader
		Dim xml As String = reader.ReadToEnd()

		' Note it is not necessary to call Close() on any of the classes
		' as the .NET Framework will dispose of them automatically when
		' they go out of scope at the end of the function.
		' You can get more advanced and Close/Dispose them manually for
		' more efficiency, though.
		Return xml
	End Function

End Module

If you want to continue, give this a try and let me know. Next we can do the actual parsing of the data.

  • 0

To be honest, you're really not going to get far with VB6. I'd actually recommend that since you're taking the time to learn a language, that you just start with C#. VB.NET really is quite a transitional language from people that know VB6 [which you, by any stretch of the imagination, do not] to C#. C# is more widely supported and opens more opportunities for you down the line.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I was thinking, and was going to post, almost exactly what @Brandon Hjust posted!   WARNING: possible spoilers I also love these videos she makes:   
    • The Witcher 4 tech demo shows off the RPG in action on a base PS5 at 60FPS by Pulasthi Ariyasinghe Epic Games' The State of Unreal 2025 keynote happened today, giving a look at its latest improvements to the Unreal Engine, and other developments and partnerships that the Fortnite maker is involved in. The show kicked things off with a bang, giving fans a live on-stage presentation of The Witcher 4 alongside developer CD Projekt RED. Seen below, the tech demo of the hugely anticipated RPG features the new trilogy's protagonist, Ciri, as she explores Kovir, the new mainland that CD Projekt is letting players explore. Following a monster trail, Ciri and her horse Kelpie go through mountains and forests before reaching the town of Valdrest. Surprisingly, the demo is said to be running on a base PlayStation 5, and it even manages to stay at 60 frames per second despite the stunning visuals. The studio said that the technologies it is using will benefit all platforms that it is targeting for the RPG. The Witcher 4 is coming to PC, Xbox Series X|S, and PlayStation 5 consoles, though a release date has not been revealed yet. "We started our partnership with Epic Games to push open-world game technology forward. To show this early look at the work we’ve been doing using Unreal Engine running at 60 FPS on PlayStation 5, is a significant milestone — and a testament of the great cooperation between our teams," said joint CEO of CD Projekt RED Michał Nowakowski. "But we're far from finished. I look forward to seeing more advancements and inspiring technology from this partnership as development of The Witcher 4 on Unreal Engine 5 continues." The demo showcases tech like Unreal Animation Framework, Nanite Foliage rendering, MetaHuman technology with Mass AI crowd scaling, and more from Epic Games' latest engine developments. Unreal Engine 5.6 is said to include many of these improvements, letting any developer use the tools on their games for better visuals and optimizations.
    • The same guy who promised AGI in a year, and later he said: yes, but no really.
    • Microsoft and security. 🤣 One day, I received a big bill from Microsoft. I checked the log, and the log (not Azure Premium) only lasted a few weeks, so I was unable to find any information about what happened. I checked the bill, and it showed me that somebody (no information) created a big virtual machine for many weeks, then finally deleted it. I contacted support, and they told me that I will get my money back. 8 months later, it never happened. However, the invoices show some weird movements. They indeed did the reverse, but only in the system, but my CC never got the money back. I had a fight with my bank, and my bank finally showed me records that Microsoft never tried to return my money. What happened, who hacked it, and how? Microsoft was unable to answer. My account had a DFA. Conclusion: I should have reported it to my CC.
  • Recent Achievements

    • Week One Done
      Adam Todd earned a badge
      Week One Done
    • Contributor
      Ed B went up a rank
      Contributor
    • One Month Later
      moporcho earned a badge
      One Month Later
    • One Month Later
      Parotel earned a badge
      One Month Later
    • Reacting Well
      Cryptecks earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      202
    2. 2
      snowy owl
      144
    3. 3
      ATLien_0
      133
    4. 4
      Xenon
      120
    5. 5
      +FloatingFatMan
      106
  • Tell a friend

    Love Neowin? Tell a friend!