Hi all,
I'm trying to create a function that converts a zipcode with house number to an address.
I found a web service that does this, but I don't get the function to work.
I don't understand how to parse the XML result.
My current code (which returns nothing) is:
Possible XML results are:
{"status":"error","errorcode":6,"errormessage":"invalid api-key"}
Or:
{"status":"ok","results":[{"nlzip6":"value","streetname":"value","city":"value","municipality":"value","province":"value","latitude":"value","longitude":"value","phoneareacode":"value"}]}
I would like to understand how to access these results.
I want to read the 'status' value:
- in case of error return the reason specified in 'errormessage'
- in case of ok, return the result, for example the streetname value.
Can anyone help me out with this?
I'm trying to create a function that converts a zipcode with house number to an address.
I found a web service that does this, but I don't get the function to work.
I don't understand how to parse the XML result.
My current code (which returns nothing) is:
Code:
Function findAddress() As String
Dim xmldoc As MSXML2.DOMDocument60
Dim xmlNode As MSXML2.IXMLDOMNode
Dim xmlNodeList As MSXML2.IXMLDOMNodeList
Dim myNode As MSXML2.IXMLDOMNode
'Assemble the query string
Dim strQuery As String
strQuery = "http://api.postcodes.nl/1.0/address/?"
strQuery = strQuery & "apikey=key"
strQuery = strQuery & "&nlzip6=1234AB"
strQuery = strQuery & "&streetnumber=10"
'define XML and HTTP components
Dim xmlService As New MSXML2.XMLHTTP60
xmlService.Open "GET", strQuery, False
xmlService.Send
Set xmldoc = New MSXML2.DOMDocument60
xmldoc.async = False
xmldoc.LoadXML (xmlService.responseText)
Set xmlNodeList = xmldoc.getElementsByTagName("*")
For Each xmlNode In xmlNodeList
For Each myNode In xmlNode.ChildNodes
If myNode.NodeType = NODE_TEXT Then
Debug.Print xmlNode.nodeName & "=" & xmlNode.Text
End If
Next myNode
Next xmlNode
Set xmldoc = Nothing
End Function
Possible XML results are:
{"status":"error","errorcode":6,"errormessage":"invalid api-key"}
Or:
{"status":"ok","results":[{"nlzip6":"value","streetname":"value","city":"value","municipality":"value","province":"value","latitude":"value","longitude":"value","phoneareacode":"value"}]}
I would like to understand how to access these results.
I want to read the 'status' value:
- in case of error return the reason specified in 'errormessage'
- in case of ok, return the result, for example the streetname value.
Can anyone help me out with this?