KernelK
Registered User.
- Local time
- Today, 15:10
- Joined
- Oct 3, 2006
- Messages
- 173
I've looked through all the posts here for an answer but havnt found one that I can use, so sorry if you guys have answered this before and I just cannot locate it. I am trying to parse XML data that is retrieved from an URL. I found code on MSDN that pertains to VB but I cannot modify it to work in Access as Access does not use the onreadystatechange event. When stepping through the code the class module never executes a line, and if I change the async value to False to get the response processed, the oNode variable returns as nothing. Could you help me with correcting this code, or perhaps provide me help with the solution that you found? Thanks in advance.
MSDN Article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/418fd944-9256-4e61-8d7b-5ea41b2ca3cc.asp
My modified code (Blank DB with 1 form [form1] that has 1 textbox and 1 button; and the class module (modified)):
'Form_Form1
Option Compare Database
Option Explicit
Public oHttpReq As XMLHTTP30
Public oXMLDoc As DOMDocument30
Private Sub MakeRequest(ByVal isAsync As Boolean)
Set oHttpReq = New XMLHTTP30
Dim xhrHandler As myHttpRequestHandlers
Dim url As String
If isAsync = True Then
Set xhrHandler = New myHttpRequestHandlers
' Set a readyStateChange handler.
oHttpReq.OnReadyStateChange = xhrHandler
End If
' Construct the URL from user input.
url = "http://synergidev/api/api.vsd.php?q=users"
' Open a connection and set up a request to the server.
oHttpReq.Open "GET", url, isAsync
' Send the request to the server.
oHttpReq.send
' In a synchronous call, we must call ProcessResponse. In an
' asynchronous call, the OnReadyStateChange handler calls
' ProcessResponse.
If isAsync = False Then
ProcessResponse
End If
End Sub
Public Sub ProcessResponse()
' Receive the response from the server.
Set oXMLDoc = oHttpReq.responseXML
Dim oNode
' Display the server response to the user.
Set oNode = oXMLDoc.selectSingleNode("//username")
If oNode Is Nothing Then
Me.txtBox = "Requested information not found."
Else
Me.txtBox = oNode.Text
End If
End Sub
Private Sub cmdButton_Click()
MakeRequest (True)
End Sub
Private Sub Form_Load()
Me.txtBox = ""
End Sub
'myHttpRequestHandlers
Option Compare Database
Option Explicit
Sub OnReadyStateChange()
If Forms("form1")!oHttpReq.readyState = 4 Then
Forms("form1").ProcessResponse
End If
End Sub
MSDN Article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/418fd944-9256-4e61-8d7b-5ea41b2ca3cc.asp
My modified code (Blank DB with 1 form [form1] that has 1 textbox and 1 button; and the class module (modified)):
'Form_Form1
Option Compare Database
Option Explicit
Public oHttpReq As XMLHTTP30
Public oXMLDoc As DOMDocument30
Private Sub MakeRequest(ByVal isAsync As Boolean)
Set oHttpReq = New XMLHTTP30
Dim xhrHandler As myHttpRequestHandlers
Dim url As String
If isAsync = True Then
Set xhrHandler = New myHttpRequestHandlers
' Set a readyStateChange handler.
oHttpReq.OnReadyStateChange = xhrHandler
End If
' Construct the URL from user input.
url = "http://synergidev/api/api.vsd.php?q=users"
' Open a connection and set up a request to the server.
oHttpReq.Open "GET", url, isAsync
' Send the request to the server.
oHttpReq.send
' In a synchronous call, we must call ProcessResponse. In an
' asynchronous call, the OnReadyStateChange handler calls
' ProcessResponse.
If isAsync = False Then
ProcessResponse
End If
End Sub
Public Sub ProcessResponse()
' Receive the response from the server.
Set oXMLDoc = oHttpReq.responseXML
Dim oNode
' Display the server response to the user.
Set oNode = oXMLDoc.selectSingleNode("//username")
If oNode Is Nothing Then
Me.txtBox = "Requested information not found."
Else
Me.txtBox = oNode.Text
End If
End Sub
Private Sub cmdButton_Click()
MakeRequest (True)
End Sub
Private Sub Form_Load()
Me.txtBox = ""
End Sub
'myHttpRequestHandlers
Option Compare Database
Option Explicit
Sub OnReadyStateChange()
If Forms("form1")!oHttpReq.readyState = 4 Then
Forms("form1").ProcessResponse
End If
End Sub