Link to home
Start Free TrialLog in
Avatar of JasonJasonJasonJason
JasonJasonJasonJason

asked on

Get UPS XML responses to ASP Variable

Hello.

I have code that gets tracking information from UPS via XML code.  The outgoing request and incoming response seem to be functioning correctly.  However , I need to assign the incoming responses to classic ASP variables.  Each response line should be it's own variable named after the <tag>.  Can this be accomplished?  Below is the ASP file I use to send the XML and also a copy of the response.  

PLEASE HELP!
<html>
<head>
<title>Untitled Document</title>
 
</head>
 
------------------------------------------------RESPONSE-------------------------------------------------
- <html>
- <head>
  <title>Untitled Document</title> 
  </head>
  <?xml version="1.0" ?> 
- <TrackResponse>
- <Response>
- <TransactionReference>
  <CustomerContext>gd</CustomerContext> 
  <XpciVersion>1.0001</XpciVersion> 
  </TransactionReference>
  <ResponseStatusCode>1</ResponseStatusCode> 
  <ResponseStatusDescription>Success</ResponseStatusDescription> 
  </Response>
- <Shipment>
- <Shipper>
  <ShipperNumber>5W011F</ShipperNumber> 
- <Address>
  <AddressLine1>1572 GOODYEAR AVE</AddressLine1> 
  <AddressLine2>SUITE D</AddressLine2> 
  <City>VENTURA</City> 
  <StateProvinceCode>CA</StateProvinceCode> 
  <PostalCode>93003 6449</PostalCode> 
  <CountryCode>US</CountryCode> 
  </Address>
  </Shipper>
- <ShipTo>
- <Address>
  <City>BRICK</City> 
  <StateProvinceCode>NJ</StateProvinceCode> 
  <PostalCode>087242704</PostalCode> 
  <CountryCode>US</CountryCode> 
  </Address>
  </ShipTo>
- <ShipmentWeight>
- <UnitOfMeasurement>
  <Code>LBS</Code> 
  </UnitOfMeasurement>
  <Weight>1.00</Weight> 
  </ShipmentWeight>
- <Service>
  <Code>002</Code> 
  <Description>2ND DAY AIR</Description> 
  </Service>
  <ShipmentIdentificationNumber>1Z5W011F0298909629</ShipmentIdentificationNumber> 
  <PickupDate>20080917</PickupDate> 
- <Package>
  <TrackingNumber>1Z5W011F0298909629</TrackingNumber> 
- <Activity>
- <ActivityLocation>
- <Address>
  <City>BRICK</City> 
  <StateProvinceCode>NJ</StateProvinceCode> 
  <PostalCode>08724</PostalCode> 
  <CountryCode>US</CountryCode> 
  </Address>
  <Code>MQ</Code> 
  <Description>PORCH</Description> 
  </ActivityLocation>
- <Status>
- <StatusType>
  <Code>D</Code> 
  <Description>DELIVERED</Description> 
  </StatusType>
- <StatusCode>
  <Code>FS</Code> 
  </StatusCode>
  </Status>
  <Date>20080919</Date> 
  <Time>144600</Time> 
  </Activity>
- <PackageWeight>
- <UnitOfMeasurement>
  <Code>LBS</Code> 
  </UnitOfMeasurement>
  <Weight>1.00</Weight> 
  </PackageWeight>
  </Package>
  </Shipment>
  </TrackResponse>
  <body /> 
  </html>
 
 
<%
strXML = strXML & "<?xml version='1.0'?>"
strXML = strXML & "<AccessRequest xml:lang='en-US'>"
strXML = strXML & "<AccessLicenseNumber>BC30FCBD42744B48</AccessLicenseNumber>"
strXML = strXML & "<UserId>websql08724</UserId>"
strXML = strXML & "<Password>1nt3rn3t</Password>"
strXML = strXML & "</AccessRequest>"
strXML = strXML & "<?xml version='1.0'?> "
strXML = strXML & "<TrackRequest xml:lang='en-US'> "
strXML = strXML & " <Request> "
strXML = strXML & " <TransactionReference> "
strXML = strXML & " <CustomerContext>gd</CustomerContext> "
strXML = strXML & " <XpciVersion>1.0001</XpciVersion> "
strXML = strXML & " </TransactionReference> "
strXML = strXML & " <RequestAction>Track</RequestAction> "
strXML = strXML & " <RequestOption /> "
strXML = strXML & " </Request> "
strXML = strXML & " <TrackingNumber>1Z5W011F0298909629</TrackingNumber> "
strXML = strXML & "</TrackRequest> "
 
Dim xmlhttp 
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP") 
 
 
xmlhttp.Open "POST","https://www.ups.com/ups.app/xml/Track?",false 
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
xmlhttp.send strXML 
 
responsexml = xmlhttp.responseText 
 
response.contenttype = "text/xml"
response.write responsexml
 
 %>
<body>
 
</body>
</html>

Open in new window

Avatar of mmaxwell43534
mmaxwell43534
Flag of United States of America image

All you need to do is this:
Dim objXml, address1, address2
Set objXml = CreateObject("MSXML2.DOMDocument")
objXml.Load(xmlhttp.responseXML)
address1 = objXml.getElementsByTagName("AddressLine1").text
address2 = objXml.getElementsByTagName("AddressLine2").text

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mmaxwell43534
mmaxwell43534
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial