Avatar of net-workx
net-workx
Flag for United Kingdom of Great Britain and Northern Ireland

asked on 

Read XML Response From ASP Classic

I have an integration with PCA predict that calls a function and verifies an address, the function is here:

function CleansePlus_Batch_Cleanse_v1_00(Key, Addresses, MatchLevel, Lines, SeparateOutCompanyAndDepartment, SeparateOutTownCountyPostcode)

      dim strUrl
      dim objHttp
      dim rst

      'Build the url
      strUrl = "http://services.postcodeanywhere.co.uk/CleansePlus/Batch/Cleanse/v1.00/recordset.ws?"
      strUrl = strUrl & "&Key=" & Server.UrlEncode(Key)
      strUrl = strUrl & "&Addresses=" & Server.UrlEncode(Addresses)
      strUrl = strUrl & "&MatchLevel=" & Server.UrlEncode(MatchLevel)
      strUrl = strUrl & "&Lines=" & Server.UrlEncode(Lines)
      strUrl = strUrl & "&SeparateOutCompanyAndDepartment=" & Server.UrlEncode(SeparateOutCompanyAndDepartment)
      strUrl = strUrl & "&SeparateOutTownCountyPostcode=" & Server.UrlEncode(SeparateOutTownCountyPostcode)

      'Make the request
      'set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
      set objHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
      objHttp.Open "GET", strUrl, false
      objHttp.Send

      'Response.Write "Response From Web Service: " & Server.HTMLEncode(objHttp.ResponseText) & "<br>"
      Response.Write "Response From Web Service: " & objHttp.ResponseText & "<br>"

      'Create the recordset
      set rst = Server.CreateObject("ADODB.Recordset")
      rst.Open objHttp.responseStream

      'Check for an error
      if rst.Fields.Count=4 then
         if rst.Fields(0).Name="Error" then
           Err.Raise rst.Fields(0), "Webservice Error", rst.Fields(1)
        end if
      end if

      'Return the recordset
      set CleansePlus_Batch_Cleanse_v1_00 = rst

      'FYI: The recordset returns the following columns:
      'Udprn
      'Company
      'Department
      'Line1
      'Line2
      'Line3
      'Line4
      'Line5
      'PostTown
      'County
      'Postcode
      'Barcode
      'Type
      'DeliveryPointSuffix
      'SubBuilding
      'BuildingName
      'BuildingNumber
      'PrimaryStreet
      'SecondaryStreet
      'DoubleDependentLocality
      'DependentLocality
      'PoBox
      'PrimaryStreetName
      'PrimaryStreetType
      'SecondaryStreetName
      'SecondaryStreetType
      'Outcome

end function

Open in new window



When i call this function using:

Call CleansePlus_Batch_Cleanse_v1_00(strKey, strAddress, strMatchLevel, strLines, strSeparateOutCompanyAndDepartment, strSeparateOutTownCountyPostcode)

Open in new window


I get the response (only viewable from View Source in a browser or using Server.HTMLEncode first) of:

<?xml version="1.0" encoding="UTF-8" ?>
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
  <s:Schema id="RowsetSchema" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882">
    <s:ElementType name="row" content="eltOnly">
      <s:AttributeType name="Udprn" rs:number="1" />
      <s:AttributeType name="Company" rs:number="2" />
      <s:AttributeType name="Department" rs:number="3" />
      <s:AttributeType name="Line1" rs:number="4" />
      <s:AttributeType name="Line2" rs:number="5" />
      <s:AttributeType name="Line3" rs:number="6" />
      <s:AttributeType name="Line4" rs:number="7" />
      <s:AttributeType name="Line5" rs:number="8" />
      <s:AttributeType name="PostTown" rs:number="9" />
      <s:AttributeType name="County" rs:number="10" />
      <s:AttributeType name="Postcode" rs:number="11" />
      <s:AttributeType name="Barcode" rs:number="12" />
      <s:AttributeType name="Type" rs:number="13" />
      <s:AttributeType name="DeliveryPointSuffix" rs:number="14" />
      <s:AttributeType name="SubBuilding" rs:number="15" />
      <s:AttributeType name="BuildingName" rs:number="16" />
      <s:AttributeType name="BuildingNumber" rs:number="17" />
      <s:AttributeType name="PrimaryStreet" rs:number="18" />
      <s:AttributeType name="SecondaryStreet" rs:number="19" />
      <s:AttributeType name="DoubleDependentLocality" rs:number="20" />
      <s:AttributeType name="DependentLocality" rs:number="21" />
      <s:AttributeType name="PoBox" rs:number="22" />
      <s:AttributeType name="PrimaryStreetName" rs:number="23" />
      <s:AttributeType name="PrimaryStreetType" rs:number="24" />
      <s:AttributeType name="SecondaryStreetName" rs:number="25" />
      <s:AttributeType name="SecondaryStreetType" rs:number="26" />
      <s:AttributeType name="Outcome" rs:number="27" />
    </s:ElementType>
  </s:Schema>
  <rs:data xmlns:rs="urn:schemas-microsoft-com:rowset">
    <z:row Udprn="744546" Company="" Department="" Line1="*** Thorncliffe Road" Line2="" Line3="" Line4="" Line5="" PostTown="Birmingham" County="West Midlands" Postcode="*** 9DB" Barcode="(***9DB1RR)" Type="Residential" DeliveryPointSuffix="1R" SubBuilding="" BuildingName="" BuildingNumber="22" PrimaryStreet="Thorncliffe Road" SecondaryStreet="" DoubleDependentLocality="" DependentLocality="" PoBox="" PrimaryStreetName="Thorncliffe" PrimaryStreetType="Road" SecondaryStreetName="" SecondaryStreetType="" Outcome="StrictProperty" xmlns:z="#RowsetSchema" />
  </rs:data>
</xml>

Open in new window


My question is how do i now get this feed into ASP so that i can read the responses back and save into a new table or update the current table with addresses?

Also, the original function didnt have:

      'Response.Write "Response From Web Service: " & Server.HTMLEncode(objHttp.ResponseText) & "<br>"
      Response.Write "Response From Web Service: " & objHttp.ResponseText & "<br>"

Open in new window


I entered these to see the response coming back from the web service, however if i remove/comment those lines out nothing is returned either in the browser or in "View Source"

Can anyone help with reading the response from this web service?

Thanks!
ASPVB ScriptWeb Languages and StandardsXMLWeb Development

Avatar of undefined
Last Comment
net-workx

8/22/2022 - Mon