I am beginning the process of integrating with a USPS webservice. Based on my request XML, I will receive a response that contains the label image which is base64 encoded. Here is a sample of what I receive back:
<?xml version="1.0"?>
<DeliveryConfirmationV3.0R
esponse>
<DeliveryConfirmationNumbe
r>42038119
9101805213
9071268096
51</Delive
ryConfirma
tionNumber
>
<DeliveryConfirmationLabel
>SUkqAAgAA
AASAP4ABAA
BAAAAAAAAA
AABBAABAAA
ApAYAAAEBB
AABAAAAmAg
AAAIB
AwABAAAAAQAAAAMBAwABAAAABA
AAAAYBAwAB
AAAAAAAAAA
oBAwABAAAA
AgAAABEB
[truncated to keep post short]
DeliveryConfirmationLabel>
<ToName>Joe Customer</ToName>
<ToFirm></ToFirm>
<ToAddress1>STE 201</ToAddress1>
<ToAddress2>6060 PRIMACY KWY</ToAddress2>
<ToCity>Memphis</ToCity>
<ToState>TN</ToState>
<ToZip5>38119</ToZip5>
<ToZip4>5718</ToZip4>
<Postnet>38119571851</Post
net>
</DeliveryConfirmationV3.0
Response>
I know how to extract the element from the XML file that I need (<DeliveryConfirmationLabe
l>), but how can I convert this into something that the user can view in a browser. It can either be a .tif or a .pdf based on what I request.
I read this article:
http://www.perfectxml.com/articles/xml/binary.asp and it seemed to describe exactly what I am trying to do, but it suggested building a COM object to accomplish it. This was my best attempt to convert it to straight ASP:
<%
strXML = {RESPONSE FROM WEBSERVICE SHOWN ABOVE}"
Set oXMLDoc = Server.CreateObject("Msxml
2.FreeThre
adedDOMDoc
ument.4.0"
)
If IsObject(oXMLDoc) Then
oXMLDoc.Async = False
If oXMLDoc.LoadXML(strXML) Then
'Response.Write "loaded xml"
Set oSingleNode = oXMLDoc.selectSingleNode("
//Delivery
Confirmati
onLabel")
If oSingleNode Is Nothing Then
Response.Write "can't find the node"
Else
'Response.Write oSingleNode.Text
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Set objStream = Server.CreateObject("ADODB
.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.Write oSingleNode.nodeTypedValue
objStream.SaveToFile Server.MapPath("test.tif")
, adSaveCreateOverWrite
objStream.Close
Set objStream = Nothing
End If
Else
Response.Write "unable to load xml"
End If
Else
Response.Write "<b>Unable To Create Object</b> "
End If
%>
I get the error: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. This is the line that produces the error:
objStream.Write oSingleNode.nodeTypedValue