본문 바로가기
Developer/asp

Classic ASP XML parsing /UPS RATE API

by MindOpener 2018. 4. 17.
반응형

미국 UPS 의 RATE API 를 사용해야 해서 


function UPSverify( originalTotal, s_zp, Service)

'url = "https://wwwcie.ups.com/ups.app/xml/Rate"

url = "https://onlinetools.ups.com/ups.app/xml/Rate"

 


  Response.Buffer = True

  Dim objXMLHTTP, xml


  ' Create an xmlhttp object:

  Set xml = Server.CreateObject("Microsoft.XMLHTTP")

  ' Or, for version 3.0 of XMLHTTP, use:

  ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")


  ' Opens the connection to the remote server.

  xml.Open "POST", url, False

  'xml.setRequestHeader "Content-Type", "text/xml"

  xml.setRequestHeader "Content-type", "application/x-www-form-urlencoded"

  ' Actually Sends the request and returns the data:

  xml.Send(xmlData)


  'Display the HTML both as HTML and as text

 ' Response.Write "<h1>The HTML text</h1><xmp>"

  resposneXmlData =  xml.responseText

  ' Response.Write "</xmp><p><hr><p><h1>The HTML Output</h1>"

UPSverify = ParseXml(resposneXmlData)

   

  Set xml = Nothing

End function



Function ParseXml(strXML)

Dim oXML, oNode, sKey, sValue

 

Set oXML = Server.CreateObject("MSXML2.DomDocument.6.0")

oXML.LoadXML(strXML)

'var currentvalue = $xml.find( "RatedShipment" ).children( "TotalCharges" ).children( "MonetaryValue" ).text() ; RatingServiceSelectionResponse/RatedShipment/TotalCharges/MonetaryValue

For Each oNode In oXML.SelectNodes("/RatingServiceSelectionResponse/RatedShipment/TotalCharges/MonetaryValue")


sKey = oNode.GetAttribute("name")

  sValue = oNode.Text

  ParseXml = sValue 

Next

 

Set oXML = Nothing

end Function

반응형