• 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

    • Microsoft: Edge performs better than Google Chrome on Windows in ad blocking and more by Sayan Sen Recently, Google put out a performance report for its Chrome web browser explaining how the changes it made to memory management and caching mechanisms managed to make it the fastest it has ever been. Google is not the only one to do it recently, as Microsoft too made similar claims about performance boosts earlier in the year in April. If you were trying to pick between the two, Microsoft is trying to make it easy for you to decide. In a recent blog post titled "Microsoft Edge browser: The fast, smart alternative to Chrome," the tech giant has laid out all the reasons you should pick its browser over Google Chrome. As pointed out in our first paragraph, performance is something these companies often try to brag about, and for good reasons, because people do want to get a snappier experience. This could explain why Mozilla's Firefox has been left behind over time in terms of market share, as it has not been able to keep up with Chromium-based browsers in the performance department. Microsoft says that Edge is better for your Windows PC than Google's Chrome, as it is a "Microsoft product" that "integrates closely with Microsoft Windows," which helps with "performance benefits." Besides that, the Redmond company also points out other "speed and efficiency" features of Edge, like sleeping tabs that helped save 'over 7 trillion megabytes of memory' in 2024. And Edge is also said to "help with smooth performance so that add-ons like Microsoft Translator, ad blockers, and password managers work efficiently." Microsoft adds how the "optimized architecture of Edge helps with lower CPU load and overall resource consumption, providing a smooth experience, particularly on low-spec devices" and also how its "efficient resource allocation helps minimize slowdowns." Aside from performance, productivity is another area where Microsoft says Edge excels. That is thanks to Microsoft 365 integration and other AI tools. In the end of the blog post, Microsoft suggests that this is the right time to switch to Edge from Google Chrome. You can find the post here on Microsoft's official website.
    • At some point, hardware becomes obsolete and we cant blame vendors for dropping support. Much of the models dropped, run Intel hardware which means they can install something else on the device if they truly want to keep using it.
    • Well, that was fun: PS C:\WINDOWS\system32> Install-Script -Name Set-InetpubFolderAcl WARNING: Unable to download from URI 'https://go.microsoft.com/fwlin...627338&clcid=0x409' to ''. WARNING: Unable to download the list of available providers. Check your internet connection. PackageManagement\Install-PackageProvider : No match was found for the specified search criteria for the provider 'NuGet'. The package provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified package has the tags. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7468 char:21 + ... $null = PackageManagement\Install-PackageProvider -Name $script:N ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception + FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider PackageManagement\Import-PackageProvider : No match was found for the specified search criteria and provider name 'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7474 char:21 + ... $null = PackageManagement\Import-PackageProvider -Name $script:Nu ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (NuGet:String) [Import-PackageProvider], Exception + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider WARNING: Unable to download from URI 'https://go.microsoft.com/fwlin...627338&clcid=0x409' to ''. WARNING: Unable to download the list of available providers. Check your internet connection. PackageManagement\Get-PackageProvider : Unable to find package provider 'NuGet'. It may not be imported yet. Try 'Get-PackageProvider -ListAvailable'. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7478 char:30 + ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvider], Exceptio n + FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider Install-Script : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed. At line:1 char:1 + Install-Script -Name Set-InetpubFolderAcl + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: ( [Install-Script], InvalidOperationException + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Script
    • Because Apple has never discontinued Mac models before now?
  • Recent Achievements

    • Week One Done
      abortretryfail earned a badge
      Week One Done
    • First Post
      Mr bot earned a badge
      First Post
    • First Post
      Bkl211 earned a badge
      First Post
    • One Year In
      Mido gaber earned a badge
      One Year In
    • One Year In
      Vladimir Migunov earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      488
    2. 2
      +FloatingFatMan
      257
    3. 3
      snowy owl
      247
    4. 4
      ATLien_0
      222
    5. 5
      +Edouard
      191
  • Tell a friend

    Love Neowin? Tell a friend!