I'm just getting my feet wet with XML. I've been coding html and asp since '95. So any help that anyone can provide will be greatly appreciated. (I started reading the XML Developers Handbook and had to use toothpicks to keep my eyes open) So here goes, below you'll see some sample code of what UPS returns when I submit a tracking request: <TrackResponse> <Response> <TransactionReference> <CustomerContext>Mocap1</CustomerContext> <XpciVersion>1.0001</XpciVersion> </TransactionReference> <ResponseStatusCode>1</ResponseStatusCode> <ResponseStatusDescription>Success</ResponseStatusDescription> </Response> <Shipment> <Shipper> <ShipperNumber>669668</ShipperNumber> <Address> <AddressLine1>111 INDUSTRIAL DR</AddressLine1> <City>PARK HILLS</City> <StateProvinceCode>MO</StateProvinceCode> <PostalCode>63601 3170</PostalCode> <CountryCode>US</CountryCode> </Address> </Shipper> <ShipTo> <Address> <AddressLine1>JACK</AddressLine1> <AddressLine2>2295 AUTOPLEX DRIVE</AddressLine2> <City>BOSSIER CITY</City> <StateProvinceCode>LA</StateProvinceCode> <PostalCode>71111</PostalCode> <CountryCode>US</CountryCode> </Address> </ShipTo> <Service> <Code>003</Code> <Description>GROUND</Description> </Service> <ReferenceNumber> <Code>01</Code> <Value>51038</Value> </ReferenceNumber> <ReferenceNumber> <Code>01</Code> <Value>F15085</Value> </ReferenceNumber> <ShipmentIdentificationNumber>1Z6696680305103812</ShipmentIdentificationNumber> <PickupDate>20040415</PickupDate> <Package> <TrackingNumber>1Z6696680305103812</TrackingNumber> <Activity> <ActivityLocation> <Address> <City>BOSSIER CITY</City> <StateProvinceCode>LA</StateProvinceCode> <PostalCode>71111</PostalCode> <CountryCode>US</CountryCode> </Address> <Code>M3</Code> <Description>FRONT DESK</Description> <SignedForByName>NORRIS</SignedForByName> </ActivityLocation> <Status> <StatusType> <Code>D</Code> <Description>DELIVERED</Description> </StatusType> <StatusCode> <Code>KB</Code> </StatusCode> </Status> <Date>20040419</Date> <Time>094600</Time> </Activity> <Activity> <ActivityLocation> <Address> <City>SHREVEPORT</City> <StateProvinceCode>LA</StateProvinceCode> <CountryCode>US</CountryCode> </Address> </ActivityLocation> <Status> <StatusType> <Code>I</Code> <Description>OUT FOR DELIVERY</Description> </StatusType> <StatusCode> <Code>DS</Code> </StatusCode> </Status> <Date>20040419</Date> <Time>070000</Time> </Activity> <Activity> <ActivityLocation> <Address> <City>SHREVEPORT</City> <StateProvinceCode>LA</StateProvinceCode> <CountryCode>US</CountryCode> </Address> </ActivityLocation> <Status> <StatusType> <Code>I</Code> <Description>ARRIVAL SCAN</Description> </StatusType> <StatusCode> <Code>AR</Code> </StatusCode> </Status> <Date>20040419</Date> <Time>060000</Time> </Activity> <Activity> <ActivityLocation> <Address> <City>JACKSON</City> <StateProvinceCode>MS</StateProvinceCode> <CountryCode>US</CountryCode> </Address> </ActivityLocation> <Status> <StatusType> <Code>I</Code> <Description>DEPARTURE SCAN</Description> </StatusType> <StatusCode> <Code>DP</Code> </StatusCode> </Status> <Date>20040416</Date> <Time>225500</Time> </Activity> <Activity> <ActivityLocation> <Address> <City>JACKSON</City> <StateProvinceCode>MS</StateProvinceCode> <CountryCode>US</CountryCode> </Address> </ActivityLocation> <Status> <StatusType> <Code>I</Code> <Description>LOCATION SCAN</Description> </StatusType> <StatusCode> <Code>LC</Code> </StatusCode> </Status> <Date>20040416</Date> <Time>133756</Time> Code (markup): ... you get the idea. So what I'm looking for is a way to itterate through the response and display the tracking history to the user. I halfway understand getElementsByTagName(), selectNodes(), etc. My problem is understanding how to get to the activity section and loop through the details in such a way as to present meaningful information to the visitor. Basically, how the heck do you get down to the ActivityLocaion and Status nodes and then regurgiate them? I hope I made sense with that. It all looks so deceptively simple, but everytime I think I understand how to reference those nodes, blam, I run into a brick wall. Thanks in advance, MN
Why don't you convert yourself to PHP? With PHP 5, you can do waht you want in 5 minutes with the new module SimpleXML (as it says its very simple!!) Or you could you XPath and PHP... In ASP I can't help you....
Have you tride using the nodelist feature? For example: Dim myXMLDoc As New DOMDocument Dim myNodeLst As MSXML.IXMLDOMNodeList Set myNodeLst = myXMLDoc.getElementsByTagName("Activity")... For i = 0 to myNodeLst.Count - 1 ...Iterate... Next Code (markup): Hope this helps
PHP is still lightyears behind the Microsoft XML parser. MSXML is so easy to integrate and its features are complete. I use PHP only on the web front and I can tell you so far PHP and XML is a let down. SimpleXML as you say is simple. I'm looking more forward to libxml myself .
The XML parser in PHP 4.x always seems to work great (and fast) for whatever I've used it for. Maybe I'm just missing something by not looking at PHP 5 yet. - Shawn
In PHP we used the expat library and now we use libXML, which is much faster and powerfull. And the SimpleXML extension is definetly very powerfull and simple!
{shrug} Always was fast for me... I can parse a 2GB XML and output it to a CSV file in about 12 minutes.
Once you get some use of libxml you'll understand why it surpasses Expat. 2GB to CVS in 12 mins using Expat is pretty impressive tho, no doubt about that... What was your setup? Quad Xeon 3.2 Ghz's ?
Here is asp code that will create a simple dropdown plus a list with your results from UPS. Just change/add nodes for the information you require. <% responsexml = xmlhttp.responseText Set mydoc=Server.CreateObject("Microsoft.xmlDOM") mydoc.loadxml(responsexml) 'Create a select table from the response xml response.Write("<select name='shipping'>") 'Create A Nodelist of All The RatedShipments Set NodeList = mydoc.documentElement.selectNodes("RatedShipment") For x = 0 To NodeList.length - 1 'Service/Code 'TotalCharges/MonetaryValue response.write("<option>") Response.Write NodeList.Item(x).selectSingleNode("Service/Code").Text & " - $" & NodeList.Item(x).selectSingleNode("TotalCharges/MonetaryValue").Text & " - " & NodeList.Item(x).selectSingleNode("GuaranteedDaysToDelivery").Text response.write("</option>") Next response.Write("</select>") %> Caryl
Actually, here is the entire ASP code for UPS Rates (request and response) if anyone is interested. <% Response.Buffer=True %> <% 'dim all of our vars Dim mydoc, responsexml 'you can build the query dynamically by using request.form or request.querystring, however you want to use it strXML = "<?xml version='1.0'?><AccessRequest xml:lang='en-US'><AccessLicenseNumber>FBA4C73476F23F62</AccessLicenseNumber><UserId>cmcdar</UserId><Password>biznes1</Password></AccessRequest><?xml version='1.0'?><RatingServiceSelectionRequest xml:lang='en-US'><Request><TransactionReference><CustomerContext>Rating and Service</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference><RequestAction>Rate</RequestAction><RequestOption>shop</RequestOption></Request><PickupType><Code>01</Code></PickupType><Shipment><Shipper><Address><PostalCode>30076</PostalCode></Address></Shipper><ShipTo><Address><PostalCode>30041</PostalCode></Address></ShipTo><Service><Code>11</Code></Service><Package><PackagingType><Code>02</Code><Description>Package</Description></PackagingType><Description>Rate Shopping</Description><PackageWeight><Weight>33</Weight></PackageWeight></Package><ShipmentServiceOptions/></Shipment></RatingServiceSelectionRequest>" 'this will url encode your request 'strXML = Server.UrlEncode(strXML) 'here's where we send the stuff Dim xmlhttp Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP") xmlhttp.Open "POST","https://www.ups.com/ups.app/xml/Rate?",false xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xmlhttp.send strXML responsexml = xmlhttp.responseText Set mydoc=Server.CreateObject("Microsoft.xmlDOM") mydoc.loadxml(responsexml) 'Create a select table from the response xml response.Write("<select name='shipping'>") 'Create A Nodelist of All The RatedShipments Set NodeList = mydoc.documentElement.selectNodes("RatedShipment") For x = 0 To NodeList.length - 1 'Service/Code 'TotalCharges/MonetaryValue response.write("<option>") Response.Write NodeList.Item(x).selectSingleNode("Service/Code").Text & " - $" & NodeList.Item(x).selectSingleNode("TotalCharges/MonetaryValue").Text & " - " & NodeList.Item(x).selectSingleNode("GuaranteedDaysToDelivery").Text response.write("</option>") Next response.Write("</select>") %>
Hey mopacfan. I was looking online for a few sample codes for this same exact thing. I had trouble acutally connecting to the track application on ups, but I got that going and now the result I get is "The XML document is not well formed" I have used the sample provided by UPS and and here is how i do the xml doc. Maybe you could help me? strXML = "" strXML = strXML & "<?xml version=1.0?>" strXML = strXML & "<AccessRequest xml:lang=en-US>" strXML = strXML & "<AccessLicenseNumber>MYACCESSNUMBER</AccessLicenseNumber>" strXML = strXML & "<Userid>MYUSERID</Userid>" strXML = strXML & "<Password>MYPASSWORD</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>sample</CustomerContext>" strXML = strXML & "<XpciVersion>1.0001</XpciVersion>" strXML = strXML & "</TransactionReference>" strXML = strXML & "<RequestAction>Track</RequestAction>" strXML = strXML & "</Request>" strXML = strXML & "<TrackingNumber>1Z12345E1512345676</TrackingNumber>" strXML = strXML & "</TrackRequest>" set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP") objHttp.open "POST", "https://www.ups.com/ups.app/xml/Track", false objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded" objHttp.Send strXML Code (markup): Any ideas? Thanks!
You need single quotes around your attributes, like en-US: strXML = strXML & "<?xml version='1.0'?> " strXML = strXML & "<TrackRequest xml:lang='en-US'> " strXML = strXML & " <Request> " strXML = strXML & " <TransactionReference> " strXML = strXML & " <CustomerContext>Example 1</CustomerContext> " strXML = strXML & " <XpciVersion>1.0001</XpciVersion> " strXML = strXML & " </TransactionReference> " strXML = strXML & " <RequestAction>Track</RequestAction> " strXML = strXML & " <RequestOption /> " strXML = strXML & " </Request> " strXML = strXML & " <TrackingNumber>1ZT9T0000000000000</TrackingNumber> " strXML = strXML & "</TrackRequest> " 'this will url encode your request 'strXML = Server.UrlEncode(strXML) 'here's where we send the stuff 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
Hello All, Looks like the discussion went into PHP stuff and he was asking about XML-ASP-UPS. I am also having the same issue and was wondering if a solution was found. The solutions shown are for Rates, I am looking for a way to display the tracking. Any examples for that? Thanks!
ggriffit, I have given the actual asp/xml code for UPS rate retrieval 2 posts up! What exactly are you looking for? Caryl
Cayrl, I am trying to get Tracking results. I think the example code you displayed above will help me figure things out. At first I did not see the second page of results. If you have a quick sample of how you format the results form the tracking side of things that would be great. Thanks, Grant
Grant, I have not used the code to retrieve Tracking from UPS. So it would take time to work that out. But, I just write the XML rate results to my database and have ASP display them from there. Caryl
It looks like all these posts are off base. Rolyrolls and ggriffit, if I understand you correctly (since this is what I'm trying to figure out as well), the issue is the data returned from ups when a package is tracked. Not what the rate of shipment is. Here is the xml that is returned from ups when a request is sent: <?xml version=""1.0""?> <TrackResponse> <Response> <TransactionReference> <CustomerContext>Acme</CustomerContext> <XpciVersion>1.0001</XpciVersion> </TransactionReference> <ResponseStatusCode>1</ResponseStatusCode> <ResponseStatusDescription>Success</ResponseStatusDescription> </Response> <Shipment> <Shipper> <ShipperNumber>124578</ShipperNumber> <Address> <AddressLine1>111 INDUSTRIAL DR</AddressLine1> <City>Allentown</City> <StateProvinceCode>MO</StateProvinceCode> <PostalCode>52487 3170</PostalCode> <CountryCode>US</CountryCode> </Address> </Shipper> <ShipTo> <Address> <AddressLine1>JACK</AddressLine1> <AddressLine2>2295 AUTOPLEX DRIVE</AddressLine2> <City>BOSSIER CITY</City> <StateProvinceCode>LA</StateProvinceCode> <PostalCode>71111</PostalCode> <CountryCode>US</CountryCode> </Address> </ShipTo> <Service> <Code>003</Code> <Description>GROUND</Description> </Service> <ReferenceNumber> <Code>01</Code> <Value>51038</Value> </ReferenceNumber> <ReferenceNumber> <Code>01</Code> <Value>F15085</Value> </ReferenceNumber> <ShipmentIdentificationNumber>1Z6696680305102154</ShipmentIdentificationNumber> <PickupDate>20040415</PickupDate> <Package> <TrackingNumber>1Z6696680305102154</TrackingNumber> <Activity> <ActivityLocation> <Address> <City>BOSSIER CITY</City> <StateProvinceCode>LA</StateProvinceCode> <PostalCode>71111</PostalCode> <CountryCode>US</CountryCode> </Address> <Code>M3</Code> <Description>FRONT DESK</Description> <SignedForByName>NORRIS</SignedForByName> </ActivityLocation> <Status> <StatusType> <Code>D</Code> <Description>DELIVERED</Description> </StatusType> <StatusCode> <Code>KB</Code> </StatusCode> </Status> <Date>20040419</Date> <Time>094600</Time> </Activity> <Activity> <ActivityLocation> <Address> <City>SHREVEPORT</City> <StateProvinceCode>LA</StateProvinceCode> <CountryCode>US</CountryCode> </Address> </ActivityLocation> <Status> <StatusType> <Code>I</Code> <Description>OUT FOR DELIVERY</Description> </StatusType> <StatusCode> <Code>DS</Code> </StatusCode> </Status> <Date>20040419</Date> <Time>070000</Time> </Activity> <Activity> <ActivityLocation> <Address> <City>SHREVEPORT</City> <StateProvinceCode>LA</StateProvinceCode> <CountryCode>US</CountryCode> </Address> </ActivityLocation> <Status> <StatusType> <Code>I</Code> <Description>ARRIVAL SCAN</Description> </StatusType> <StatusCode> <Code>AR</Code> </StatusCode> </Status> <Date>20040419</Date> <Time>060000</Time> </Activity> <Activity> <ActivityLocation> <Address> <City>JACKSON</City> <StateProvinceCode>MS</StateProvinceCode> <CountryCode>US</CountryCode> </Address> </ActivityLocation> <Status> <StatusType> <Code>I</Code> <Description>DEPARTURE SCAN</Description> </StatusType> <StatusCode> <Code>DP</Code> </StatusCode> </Status> <Date>20040416</Date> <Time>225500</Time> </Activity> <Activity> <ActivityLocation> <Address> <City>JACKSON</City> <StateProvinceCode>MS</StateProvinceCode> <CountryCode>US</CountryCode> </Address> </ActivityLocation> <Status> <StatusType> <Code>I</Code> <Description>LOCATION SCAN</Description> </StatusType> <StatusCode> <Code>LC</Code> </StatusCode> </Status> <Date>20040416</Date> <Time>133756</Time> </Activity><Activity><ActivityLocation><Address><City>JACKSON</City><StateProvinceCode>MS</StateProvinceCode><CountryCode>US</CountryCode></Address></ActivityLocation><Status><StatusType><Code>I</Code><Description>ARRIVAL SCAN</Description></StatusType><StatusCode><Code>AR</Code></StatusCode></Status><Date>20040416</Date><Time>113700</Time></Activity><Activity><ActivityLocation><Address><City>EARTH CITY</City><StateProvinceCode>MO</StateProvinceCode><CountryCode>US</CountryCode></Address></ActivityLocation><Status><StatusType><Code>I</Code><Description>DEPARTURE SCAN</Description></StatusType><StatusCode><Code>DP</Code></StatusCode></Status><Date>20040416</Date><Time>021300</Time></Activity><Activity><ActivityLocation><Address><City>EARTH CITY</City><StateProvinceCode>MO</StateProvinceCode><CountryCode>US</CountryCode></Address></ActivityLocation><Status><StatusType><Code>I</Code><Description>LOCATION SCAN</Description></StatusType><StatusCode><Code>LC</Code></StatusCode></Status><Date>20040415</Date><Time>230844</Time></Activity><Activity><ActivityLocation><Address><City>EARTH CITY</City><StateProvinceCode>MO</StateProvinceCode><CountryCode>US</CountryCode></Address></ActivityLocation><Status><StatusType><Code>I</Code><Description>UNLOAD SCAN</Description></StatusType><StatusCode><Code>UL</Code></StatusCode></Status><Date>20040415</Date><Time>225800</Time></Activity><Activity><ActivityLocation><Address><City>EARTH CITY</City><StateProvinceCode>MO</StateProvinceCode><CountryCode>US</CountryCode></Address></ActivityLocation><Status><StatusType><Code>I</Code><Description>ARRIVAL SCAN</Description></StatusType><StatusCode><Code>AR</Code></StatusCode></Status><Date>20040415</Date><Time>212600</Time></Activity><Activity><ActivityLocation><Address><City>FARMINGTON</City><StateProvinceCode>MO</StateProvinceCode><CountryCode>US</CountryCode></Address></ActivityLocation><Status><StatusType><Code>I</Code><Description>DEPARTURE SCAN</Description></StatusType><StatusCode><Code>DP</Code></StatusCode></Status><Date>20040415</Date><Time>195000</Time></Activity><Activity><ActivityLocation><Address><CountryCode>US</CountryCode></Address></ActivityLocation><Status><StatusType><Code>M</Code><Description>BILLING INFORMATION RECEIVED</Description></StatusType><StatusCode><Code>MP</Code></StatusCode></Status><Date>20040415</Date><Time>190816</Time></Activity><Activity><ActivityLocation><Address><City>FARMINGTON</City><StateProvinceCode>MO</StateProvinceCode><CountryCode>US</CountryCode></Address></ActivityLocation><Status><StatusType><Code>I</Code><Description>ORIGIN SCAN</Description></StatusType><StatusCode><Code>OR</Code></StatusCode></Status><Date>20040415</Date><Time>184440</Time></Activity><PackageWeight><UnitOfMeasurement><Code>LBS</Code></UnitOfMeasurement><Weight>7.00</Weight></PackageWeight><ReferenceNumber><Code>01</Code><Value>51038</Value></ReferenceNumber><ReferenceNumber><Code>01</Code><Value>51038-1 ACCT:F15085 PO# 70325</Value></ReferenceNumber><ReferenceNumber><Code>01</Code><Value>SHIPPED USING (FREIGHT PLUS)</Value></ReferenceNumber><ReferenceNumber><Code>01</Code><Value>SOFTWARE WWW.acme.COM</Value></ReferenceNumber> </Package> </Shipment> </TrackResponse> Code (markup): If someone has any input into parsing this xml to get the tracking data out of it using ASP, that would be amazing and I would extremely grateful.
I do not have time to totally figure this out but here is a sample of the response for UPS Rates that my above code then parses. You should be able to figure out the substitution for selecting nodes from here. Note: High Lighting below mine... Caryl