Monday, October 26, 2009

XML Extractor

Sub PullFromInternet()

'The web address at which xml is stored
URL = ""

Dim HttpReq As Object

'Declare the request for information over the internet
Set HttpReq = New WinHttpRequest

'Specify the type of HTTP request
HttpReq.Open "GET", URL, False
'or use GET instead of POST

'Specify the type of content that can be recieved
HttpReq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"

'Send the actual request
'HttpReq.send postmydata
'Note - if using GET set postmydata to ""

Dim response As String
Dim tag As String
Dim data As String
tag = "address"
response = HttpReq.ResponseText

MsgBox (extractor(tag, response))

End Sub

Function extractor(tag As String, response As String) As String
Dim tagLength As Integer

Dim mypos As Integer
Dim myposEnd As Integer
mypos = InStr(1, response, "<" & tag)
myposEnd = InStr(1, response, "<" &"/" & tag)
tagLength = Len(tag) + 2
Dim address As String
extractor = Mid(response, mypos + tagLength, (myposEnd - mypos - tagLength))

End Function

No comments:

Post a Comment

Solidworks macros eith ChatGPT

 Record a simple using thr Solidworks macro recorder, upload it to ChatGPT, and explain to ChatGPT how you want it changed:  https://youtu.b...