?
Solved

Get UPS XML responses to ASP Variable

Posted on 2008-11-11
4
Medium Priority
?
615 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:JasonJasonJasonJason
  • 2
2 Comments
 
LVL 2

Expert Comment

by:mmaxwell43534
ID: 22947384
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

0
 
LVL 2

Accepted Solution

by:
mmaxwell43534 earned 2000 total points
ID: 22947387
Also, you may want to do something like this:
If Not objXML.Load(xmlhttp.responseXML) Then
      '''there was an error loading the XML
Else
      '''parse xml here
End If

Open in new window

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question