Results 1 to 10 of 10

Thread: Simple Read XML [Resolved In Style]

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Resolved 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.

  2. #2

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Simple Read XML

    Please, can anyoe help

    ILMV

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Simple Read XML

    VB Code:
    1. Option Explicit
    2. Private XMLdoc As MSXML2.DOMDocument40
    3.  
    4. Private Sub Form_Load()
    5.  
    6.     Dim oxmlElement As IXMLDOMElement
    7.  
    8.     On Error Resume Next
    9.    
    10.     Set XMLdoc = New DOMDocument40
    11.     XMLdoc.async = False
    12.     XMLdoc.validateOnParse = False
    13.     XMLdoc.preserveWhiteSpace = False
    14.    
    15.     XMLdoc.Load "C:\temp\version.xml"
    16.    
    17.     If XMLdoc.parseError.errorCode = 0 Then
    18.         If XMLdoc.readyState <> 4 Then
    19.             Err.Description = XMLdoc.parseError.reason & vbCrLf & _
    20.             "Line: " & XMLdoc.parseError.Line & vbCrLf & _
    21.             "XML: " & XMLdoc.parseError.srcText
    22.             MsgBox Err.Description
    23.         End If
    24.     End If
    25.  
    26.     Set oxmlElement = XMLdoc.documentElement _
    27.                             .selectSingleNode("//version")
    28.  
    29.     Debug.Print oxmlElement.Text
    30.    
    31. End Sub

  4. #4

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Simple Read XML

    REmind me what references i need.

    ILMV

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Simple Read XML

    You need
    VB Code:
    1. Microsoft XML vx.x

    I have 2.6 and 3.0 on my system.

  6. #6

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Simple Read XML

    Cool, so the highest version, i have version 5.0. I guess that will have to do

    ILMV

  7. #7

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Simple Read XML

    Right i am having problems, i am getting an error saying "With variable or object varible not defined".

    VB Code:
    1. If XMLdoc.parseError.errorCode = 0 Then
    2.         If XMLdoc.readyState <> 4 Then
    3.             Err.Description = XMLdoc.parseError.reason & vbCrLf & _
    4.             "Line: " & XMLdoc.parseError.Line & vbCrLf & _
    5.             "XML: " & XMLdoc.parseError.srcText
    6.             MsgBox Err.Description '<--- ERROR
    7.         End If
    8.     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

  8. #8
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    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:
    1. Option Explicit
    2.  
    3. 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
    4.  
    5. Private Sub Form_Load()
    6. 'Download xml file
    7. URLDownloadToFile 0, "http://www.myserver.com/update.xml", App.Path & "\update.xml", 0, 0
    8.  
    9. 'Parse file
    10. Dim objXML As DOMDocument
    11. Dim objUpdate As IXMLDOMElement
    12.  
    13. Set objXML = New DOMDocument
    14.  
    15. objXML.Load App.Path & "\update.xml"
    16.  
    17. Set objUpdate = objXML.getElementsByTagName("update").Item(0)
    18.  
    19. 'Check if version is newer than ours
    20. If objUpdate.getElementsByTagName("version").Item(0).Text > App.Major & "." & App.Minor & "." & App.Revision Then
    21.     'Download update
    22.     MsgBox objUpdate.getElementsByTagName("description").Item(0).Text
    23.     URLDownloadToFile 0, objUpdate.getElementsByTagName("file").Item(0).Text, App.Path & "\update.exe", 0, 0
    24. End If
    25.  
    26. Set objUpdate = Nothing
    27. Set objXML = Nothing
    28. End Sub
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  10. #10

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    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
  •  



Click Here to Expand Forum to Full Width