• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1237
  • Last Modified:

How to Parse http.ResponseText returned from Web service

I have written a web service with a number of different functions.  One of thes functions returns an ArrayOfString.  I am in process of writing code that access this web service.  The only part I am having trouble with is how to access (parse out) the array elements from the response text or how to assign the ResponseText to an Array.  I am attaching snipet from my web service (The function in question) and a snipet from my vba client that calls the service and receives the ResponseText.  I also attached a text file of the ResponseText.


'################################################################
    '# This Funtion returns string array of road segment that 
    '# matchs Street Name, Type and Location City Zip and with range
    '################################################################

    <WebMethod(Description:="Returns true or false if it finds matching street segment", EnableSession:=False)> _
    Public Function GetArray_StreetSegment(ByVal strHnum As String, ByVal strPreDir As String, ByVal strName As String, ByVal strType As String, ByVal strcity As String, ByVal strzip As String) As String()
        Dim RetVal(10) As String
        Dim sqlCommand As String
 
        Dim strSQLcommand As String

        '-- Build the SQL command'

        strSQLcommand = "Select OBJECTID, L_F_ADD,L_T_ADD, R_F_ADD, R_T_ADD, predir, stname, sttype, locationcity, zip  from " & MyTable & " Where (("

        If strPreDir = "" Then
            strSQLcommand = strSQLcommand & "(predir = '' or predir is null)"
        Else
            strSQLcommand = strSQLcommand & "predir ='" & strPreDir & "'"
        End If
        strSQLcommand = strSQLcommand & " And StName ='" & strName & "'"

        If strType = "" Then
            strSQLcommand = strSQLcommand & " And (stType ='' or stType is null)"
        Else
            strSQLcommand = strSQLcommand & " And sttype ='" & strType & "'"
        End If
        strSQLcommand = strSQLcommand & " And LocationCity ='" & strcity & "'"
        strSQLcommand = strSQLcommand & " And Zip ='" & strzip & "') "
        strSQLcommand = strSQLcommand & " And (((L_F_ADD >=" & strHnum & " AND L_T_ADD <=" & strHnum & ")" & _
            " Or (L_F_ADD <=" & strHnum & " AND L_T_ADD >=" & strHnum & ")) Or " & _
            " ((R_F_ADD >= " & strHnum & " and R_T_ADD <= " & strHnum & ") Or  " & _
            " (R_F_ADD <= " & strHnum & "  and R_T_ADD >= " & strHnum & "))))"


        sqlCommand = strSQLcommand

        ' The data referenced is accessed through a MultiVersioned View (ESRI SDE terminology)

        Dim VersionCommand1 As New SqlCommand("sde.set_current_version", connection)
        VersionCommand1.CommandType = CommandType.StoredProcedure
        VersionCommand1.Parameters.Add("@version_name", NVarChar, 25)
        VersionCommand1.Parameters("@version_name").Value = MyVersion
        connection.Open()
        VersionCommand1.ExecuteNonQuery()

        Dim adapter As SqlDataAdapter = New SqlDataAdapter(sqlCommand, connection)
        Dim custDS As DataSet = New DataSet()

        adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
        adapter.Fill(custDS, MyTable)
        '-- Should only be one record that matches if any so only look at 0
        If custDS.Tables(0).Rows.Count > 0 Then
            RetVal(0) = custDS.Tables(0).Rows(0).Item(0).ToString
            RetVal(1) = custDS.Tables(0).Rows(0).Item(1).ToString
            RetVal(2) = custDS.Tables(0).Rows(0).Item(2).ToString
            RetVal(3) = custDS.Tables(0).Rows(0).Item(3).ToString
            RetVal(4) = custDS.Tables(0).Rows(0).Item(4).ToString
            RetVal(5) = custDS.Tables(0).Rows(0).Item(5).ToString
            RetVal(6) = custDS.Tables(0).Rows(0).Item(6).ToString
            RetVal(7) = custDS.Tables(0).Rows(0).Item(7).ToString
            RetVal(8) = custDS.Tables(0).Rows(0).Item(8).ToString
            RetVal(9) = custDS.Tables(0).Rows(0).Item(9).ToString
        Else
            RetVal(0) = "False"
        End If

        Return RetVal

    End Function

Open in new window

Webservice-Responsel.txt
0
gismanager
Asked:
gismanager
  • 2
  • 2
1 Solution
 
CSecurityCommented:
0
 
gismanagerAuthor Commented:
Not sure how to implement the xml parser examples in vba.  What I was hoping for was some simple way of loading an xml object with the xml data and then getting the attributes.  But I can't find an example that works (at least in vba).  

What I ended up doing was just creating a function called GetStringAttributes and passing it the xml string.  The code I used is below and it returns a string array of 10 elements.


'#########################################################
'# Function to parse out xml response from the
'# GetArray_StreetSegment web service call
'# returns a string array
'#########################################################

Private Function GetStringAttributes(refstring As String) As String()
    Dim answer(9) As String
    Dim s As Integer
    Dim x As Integer
    Dim y As Integer
    Dim i As Integer
    x = 0
    y = 0
    s = 1
    
    For i = 0 To 9
        x = InStr(s, refstring, "</string>")
        y = InStr(s, refstring, "<string>")
        If y > x Then
            answer(i) = ""
            s = x
        Else
            answer(i) = Mid$(refstring, (y + 8), ((x - y) - 8))
            s = x + 8
        End If
        
    Next
    GetStringAttributes = answer
  
End Function

Open in new window

0
 
CSecurityCommented:
Why VBScript? Could you do it in JavaScript, there is a lot of Javascript XML parsers out there. Try Googling, VBScript XML Parser, you'll find some samples, but you need to modify them to fit your needs. Like:
http://forum.videohelp.com/topic304523.html
http://forums.devx.com/archive/index.php/t-3442.html
http://www.visualbasicscript.com/m57661.aspx

and...
0
 
gismanagerAuthor Commented:
Must be VB for applications because it is being called within the ArcGIS application.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now