[thelist] ASP.NET Posting an xml file?
Casey Crookston
caseyc at IntelliSoftmn.com
Mon Sep 25 13:43:35 CDT 2006
Thanks Brian,
Classic ASP and .NET aside, I've hit a snag I can't seem to figure out.
In their doc/specs, they provide a sample XML file which can be used for
testing purposes. Here's what the file looks like:
<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
<AccessLicenseNumber>YOURACCESSLICENSENUMBER</AccessLicenseNumber>
<UserId>YOURUSERID</UserId>
<Password>YOURPASSWORD</Password>
</AccessRequest>
<?xml version="1.0"?>
<ShipmentConfirmRequest xml:lang="en-US">
....
</ShipmentConfirmRequest>
You can most likely spot the problem more quickly then I did. First, it
has two xml declarations. Second, it has two root elements:
AccessRequest and ShipmentConfirmRequest.
This is what they have to say about this:
~~~~~~~~~~~~~~~~~~~~~
The following examples are fabricated XML documents showing
communication with the UPS OnLine Tools server.
Each input request is made up of two separate XML request documents.
These requests are concatenated and posted to the UPS web servers using
a single HTTP Post.
When validating the request XML documents, do not treat the two
concatenated documents as a single XML document. XML parsers can not
parse two concatenated documents. Validate each XML Request separately.
UPS will separate the two documents and parse them individually. To
ensure this occurs, verify that <?xml version="1.0"?> is at the top of
each XML request document.
~~~~~~~~~~~~~~~~~~~~
Does this make any sense to you? I have read it a dozen times and I
can't figure it out.
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