Forum Moderators: open

Message Too Old, No Replies

XML Parsing is Driving Me Crazy...

XML Parsing

         

thdrought

2:29 pm on Dec 5, 2003 (gmt 0)

10+ Year Member



Hello everyone. Recently, I was tasked to create a shipping calculator for UPS and USPS. I completed it for USPS and it works great, thanks to a posting in this forun earlier. I try to use the same code with UPS, and I get errors all over the place.

My objective is to first check the returned value of RatingServiceSelectionResponse/Response/ResponseStatusCode, if 0, it's an error and I pull the error code from the return. If it's a 1, then I pull the dollar ammount out of
RatingServiceSelectionResponse/Response/RatedShipment/TotalCharges/MonetaryValue and set as a variable.

Can someone point me in the right direction. I have hardly any knowledge of XML...none of parsing.

I get my stream from UPS fine. Here is a sample of:

<?xml version="1.0"?>
- <RatingServiceSelectionResponse>
- <Response>
- <TransactionReference>
<CustomerContext>Rating and Service</CustomerContext>
<XpciVersion>1.0001</XpciVersion>
</TransactionReference>
<ResponseStatusCode>1</ResponseStatusCode>
<ResponseStatusDescription>Success</ResponseStatusDescription>
</Response>
- <RatedShipment>
+ <Service>
<Code>03</Code>
</Service>
<RatedShipmentWarning>The Remote On Demand Pickup surcharge of 0.00 (USD) has been added to the service charge.</RatedShipmentWarning>
+ <BillingWeight>
- <UnitOfMeasurement>
<Code>LBS</Code>
</UnitOfMeasurement>
<Weight>6.0</Weight>
</BillingWeight>
+ <TransportationCharges>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>14.21</MonetaryValue>
</TransportationCharges>
+ <ServiceOptionsCharges>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>0.00</MonetaryValue>
</ServiceOptionsCharges>
- <TotalCharges>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>14.21</MonetaryValue>
</TotalCharges>
<GuaranteedDaysToDelivery />
<ScheduledDeliveryTime />
+ <RatedPackage>
- <TransportationCharges>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>14.21</MonetaryValue>
</TransportationCharges>
- <ServiceOptionsCharges>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>0.00</MonetaryValue>
</ServiceOptionsCharges>
- <TotalCharges>
<CurrencyCode>USD</CurrencyCode>
<MonetaryValue>14.21</MonetaryValue>
</TotalCharges>
<Weight>5.1</Weight>
- <BillingWeight>
- <UnitOfMeasurement>
<Code>LBS</Code>
</UnitOfMeasurement>
<Weight>6.0</Weight>
</BillingWeight>
</RatedPackage>
</RatedShipment>
</RatingServiceSelectionResponse>

Here is the code I started to parse this out:

'Parsing response
set xmlDoc = Server.CreateObject("MSxml2.FreeThreadedDOMDocument.3.0")
xmlDoc.validateOnParse = False
xmlDoc.loadXML(xmlhttp.responseText)

If error returned, find now and set strErrorCode for later use
If xmlDoc.documentElement.Item = "ResponseStatusCode" then 'Top-level Error
Dim strErrorDescription
strError = 1
Set nodeList = xmlDoc.getElementsByTagName("Error")
Set n = nodeList.Item(0)
For i = 0 To n.childNodes.length - 1
Set e = n.childNodes.Item(i)
Select Case e.nodeName
Case "ErrorSeverity"
Case "ErrorCode"
Case "ErrorDescription"
strErrorDescription = (e.firstChild.nodeValue)
End Select
Next
End If

If strError = 1 Then
Response.Write "We cannot process your shipping charges at this time. We will continue to process your order and the final charge including shipping will be emailed to you for approval. Sorry for the inconvience.<p>"
Response.Write "Error: " & strErrorDescription
End If

' Killing variables
Set xml = Nothing
Set xmlhttp = Nothing
Set xmlDoc = Nothing
set nodeList = Nothing

mattglet

2:47 pm on Dec 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what are the errors you are receiving?

-Matt

thdrought

3:22 pm on Dec 5, 2003 (gmt 0)

10+ Year Member



HTTP 500 - Internal server error

korkus2000

3:28 pm on Dec 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could it be that this comment does not have a ' before it or was that a copy paste issue?

If error returned, find now and set strErrorCode for later use