[thelist] ASP.NET Posting an xml file?
Casey Crookston
caseyc at IntelliSoftmn.com
Mon Sep 25 13:55:46 CDT 2006
Brian,
Now that I take a better look at the xml you are creating, it is
formatted the same way. ??? When I submit the xml they gave me as a
sample, I get this error:
0FailureHard10001The XML document is not well formed
I've conformed that this is an error being returned by their server, but
so far I've not been able to figure why their sample is not well formed.
Did you run into this?
Thanks,
Casey
-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Brian Cummiskey
Sent: Monday, September 25, 2006 11:46 AM
To: thelist at lists.evolt.org
Subject: Re: [thelist] ASP.NET Posting an xml file?
Casey,
I've recently built an address verification tool via UPS. I used
Classic ASP however, so my code will obviously need to be changed.
Basically what you need to do is built a string of XML to post.
I used the following:
dim strXML
strXML = ""
strXML = strXML & "<?xml version=""1.0""?>"
strXML = strXML & "<AccessRequest xml:lang=""en-US"">"
strXML = strXML & "
<AccessLicenseNumber>xxxxxxxxxxxxxxxxxxx</AccessLicenseNumber>"
strXML = strXML & " <UserId>FOO</UserId>"
strXML = strXML & " <Password>BAR</Password>"
strXML = strXML & "</AccessRequest>"
strXML = strXML & "<?xml version=""1.0""?>"
strXML = strXML & "<AddressValidationRequest
xml:lang=""en-US"">"
strXML = strXML & " <Request>"
strXML = strXML & " <TransactionReference>"
strXML = strXML & "
<CustomerContext>TC1000201</CustomerContext>"
strXML = strXML & "
<XpciVersion>1.0002</XpciVersion>"
strXML = strXML & " </TransactionReference>"
strXML = strXML & " <RequestAction>XAV</RequestAction>"
strXML = strXML & " </Request>"
strXML = strXML & " <AddressKeyFormat>"
strXML = strXML & " <ConsigneeName>"& firstname & " " &
lastname &"</ConsigneeName>"
strXML = strXML & " <AddressLine>"& address1 &
"</AddressLine>"
strXML = strXML & " <PoliticalDivision2>"& city &
"</PoliticalDivision2>"
strXML = strXML & " <PoliticalDivision1>"& state &
"</PoliticalDivision1>"
strXML = strXML & " <PostcodePrimaryLow>"& zip &
"</PostcodePrimaryLow>"
strXML = strXML & " <CountryCode>" & country
&"</CountryCode>"
strXML = strXML & " </AddressKeyFormat>"
strXML = strXML & "<MaximumListSize>10</MaximumListSize>"
strXML = strXML & "</AddressValidationRequest>"
Then, send the post:
Set objXmlHttp = CreateObject("MSXML2.ServerXMLHTTP.3.0")
objXmlHttp.setTimeouts toResolve, toConnect, toSend,
toReceive
objXmlHttp.Open "POST", baseURL, False
objXMLHttp.Send(strXML)
Then fetch the response from UPS:
returnedxml = objXMLHttp.responseXML.XML
'Instantiate XML parser and load XML file
Set objDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")
objDoc.async = False
If Not objDoc.loadXML(returnedxml) Then
'Response.Write "Failed to load XML"
Response.Redirect "review.asp"
End If
'XML ERROR CHECK
For Each objNode1 In objDoc.selectNodes("//Response")
For Each objNode2 In objNode1.ChildNodes
Select Case objNode2.nodeName
Case "ResponseStatusCode"
If Server.HTMLEncode(objNode2.text) <> "1"
Then
'response.write "XML ERROR!"
Response.Redirect "review.asp"
Else
statustext = "Success"
End If
End select
Next
Next
If statustext = "Success" Then
show the result table here:
response.write "<div id=""avsresults"">" & vbcrlf
response.write "<table><tr><td
valign=""top"" width=""40%"">" & vbcrlf
Response.Write "<p>The following
suggestions were returned:</p>" & vbcrlf
response.write "<table>" & vbcrlf
'Walk through the XML nodes
For Each objNode1 In
objDoc.selectNodes("//AddressKeyFormat")
Response.Write "<tr><td
class=""wrap"">"
For Each objNode2 In
objNode1.ChildNodes
Select Case
objNode2.nodeName
Case
"PostcodeExtendedLow" ' don't show zip+4....
' do nothing
Case Else
Response.Write
Server.HTMLEncode(objNode2.text) & "<br />" & vbcrlf
End select
Next
Response.Write "</td></tr>" & vbcrlf
Next
response.write "</table></td><td
valign=""top"" width=""60%"">" & vbcrlf
and so on....
'Clean up
Set objHTTP = Nothing
Set objDoc = Nothing
Set objNode1 = Nothing
Set objNode2 = Nothing
I have next to zero .net experience, so i won't be much help there.
but hopefully this will get you started.
--
* * Please support the community that supports you. * *
http://evolt.org/help_support_evolt/
For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !
More information about the thelist
mailing list