|
-
Sep 5th, 2005, 01:45 PM
#1
Thread Starter
Frenzied Member
Simple Read XML [Resolved In Style]
Right first of all i have search the forums for this, and i have downloaded and """attempted""" to use every sample i can get my hands on, and with little succes.
I am modifying a small update application that needs to read an XML file to find the newest version of program of mine.
I would rather be able to read th XML directly from my website, but i have to download it then thats ok. What i am loooking for is a working sample, which can read this (XML Below) and enter the values into text box's.
Any help would be appreciated
ILMV
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<update>
<version>1.0.37</version>
<os>*</os>
<description>This update makes passwords encrypted, increasing security.</description>
<downloaddir>http://www.meltdownsoftware.co.uk/content/download/diary/goldendiary.exe</downloaddir>
</update>
Last edited by I_Love_My_Vans; Sep 5th, 2005 at 05:19 PM.
-
Sep 5th, 2005, 02:58 PM
#2
Thread Starter
Frenzied Member
Re: Simple Read XML
Please, can anyoe help
ILMV
-
Sep 5th, 2005, 03:40 PM
#3
Re: Simple Read XML
VB Code:
Option Explicit
Private XMLdoc As MSXML2.DOMDocument40
Private Sub Form_Load()
Dim oxmlElement As IXMLDOMElement
On Error Resume Next
Set XMLdoc = New DOMDocument40
XMLdoc.async = False
XMLdoc.validateOnParse = False
XMLdoc.preserveWhiteSpace = False
XMLdoc.Load "C:\temp\version.xml"
If XMLdoc.parseError.errorCode = 0 Then
If XMLdoc.readyState <> 4 Then
Err.Description = XMLdoc.parseError.reason & vbCrLf & _
"Line: " & XMLdoc.parseError.Line & vbCrLf & _
"XML: " & XMLdoc.parseError.srcText
MsgBox Err.Description
End If
End If
Set oxmlElement = XMLdoc.documentElement _
.selectSingleNode("//version")
Debug.Print oxmlElement.Text
End Sub
-
Sep 5th, 2005, 04:24 PM
#4
Thread Starter
Frenzied Member
Re: Simple Read XML
REmind me what references i need.
ILMV
-
Sep 5th, 2005, 04:28 PM
#5
Re: Simple Read XML
You need
I have 2.6 and 3.0 on my system.
-
Sep 5th, 2005, 04:29 PM
#6
Thread Starter
Frenzied Member
Re: Simple Read XML
Cool, so the highest version, i have version 5.0. I guess that will have to do
ILMV
-
Sep 5th, 2005, 04:39 PM
#7
Thread Starter
Frenzied Member
Re: Simple Read XML
Right i am having problems, i am getting an error saying "With variable or object varible not defined".
VB Code:
If XMLdoc.parseError.errorCode = 0 Then
If XMLdoc.readyState <> 4 Then
Err.Description = XMLdoc.parseError.reason & vbCrLf & _
"Line: " & XMLdoc.parseError.Line & vbCrLf & _
"XML: " & XMLdoc.parseError.srcText
MsgBox Err.Description '<--- ERROR
End If
End If
I also do not know what exactly is going on in the code. Could someone please describe the main bits, what i want is to take the <version>1.0.37</version> of the XML file in a text box 
I really appreciate all your help
ILMV
-
Sep 5th, 2005, 04:53 PM
#8
Fanatic Member
Re: Simple Read XML
OK, here's a small example for you. This first downloads the XML file, then checks if the version number is newer than the current one. If so, the file is downloaded. As you can see, this example only downloads one file finally, it does not enumerate the files to be downloaded, since I supposed you didn't need that. BTW, I changed the <downloaddir> tag to the <file> tag.
VB Code:
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Sub Form_Load()
'Download xml file
URLDownloadToFile 0, "http://www.myserver.com/update.xml", App.Path & "\update.xml", 0, 0
'Parse file
Dim objXML As DOMDocument
Dim objUpdate As IXMLDOMElement
Set objXML = New DOMDocument
objXML.Load App.Path & "\update.xml"
Set objUpdate = objXML.getElementsByTagName("update").Item(0)
'Check if version is newer than ours
If objUpdate.getElementsByTagName("version").Item(0).Text > App.Major & "." & App.Minor & "." & App.Revision Then
'Download update
MsgBox objUpdate.getElementsByTagName("description").Item(0).Text
URLDownloadToFile 0, objUpdate.getElementsByTagName("file").Item(0).Text, App.Path & "\update.exe", 0, 0
End If
Set objUpdate = Nothing
Set objXML = Nothing
End Sub
Author for Visual Basic Web Magazine
-
Sep 5th, 2005, 05:13 PM
#9
Re: Simple Read XML
My sample assumes you have MSXML4. If you don't that add a reference to the latest version (eg Microsoft XML, v3.0) you do have and change DOMDocument40 to DOMDocument30 or DOMDocument20.
-
Sep 5th, 2005, 05:17 PM
#10
Thread Starter
Frenzied Member
Re: Simple Read XML
Its official, I Love The Vader
Thank you all for your help, butthis did what i wanted it do.
ILTV <-- Even worth me changing my name for a post
W00000000000T
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|