By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,257 Members | 2,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,257 IT Pros & Developers. It's quick & easy.

UPS Address Validation with XML

Expert 100+
P: 1,221
I'm feeling like the 7th blind guy, the one feeling his way around the pile behind the elephant. I think what I am trying to do is very simple, but it's not turning out like that.

I'm trying to do real-time UPS address validation via XML. I have zero knowledge of and experience with XML. I've studied the developer's guide from UPS and created some code to produce a simple string of text that looks like this Exibit 1 below. UPS insists it must be like that. However it doesn't come close to working.

I'm working in Access/VBA. Exhibit 2 is a snippet of the code. The problem I'm having is that when I produce the XML UPS says to use, the loadXML command returns a "False" result. Which means I have no XML loaded, so the subsequent .Send is useless.

I've even put their code into a .xml file and tried to open it with a browser and it
complains that "Only one top level element is allowed in an XML document". Which actually made me feel good, because I thought that was something I understood about XML and the error made sense to me. It seems to me the UPS code has two top level elements,
<accessRequest> and <addressValidationRequest>.

When I move the </AccessRequest> to the bottom of the file, (exhibit 3) the browser is happy and displays the content. I suppose like that <accessRequest> is the only top level element. When I change my code to produce this XML, the .loadXML command works okay, but UPS chokes on it and send an Error response about badly formatted XML. I also took the UPS code and wrapped it in a made up element, <doc> </doc> so there was only 1 top level element. That made the .loadXML statement happy but UPS still sent back an error "Missing XML declaration in the XML document".

After 3 days I've pretty much given up on UPS tech support giving any real support. They eventually moved me up a level, and that guy just spit back the same code I already had, only he added the " encoding="UTF-8"" part of the code. And he reminded me I really should read the developers' manual and just do what it says.

I can't believe they are actually wrong about what their xml request should look like. Somehow we're not communicating something important. They're assuming something about my environment or something and I don't know enough to ask the right questions.

I'm developing this in Access 2003 and I've got a reference to MSXML v6.0.

Any suggestions or nuggets of wisdom would be greatly appreciated.

Thanks,
Jim Wolf


================================================== ==========
Exhibit 1: UPS' XML file
<?xml version="1.0" encoding="UTF-8"?>
<accessRequest>
<accessLicenseNumber>123abcmyaccesscode</AccessLicenseNumber>
<UserId>xxxxxx</UserId>
<Password>yyyyyy</Password>
</AccessRequest>
<?xml version="1.0" encoding="UTF-8"?>
<addressValidationRequest xml:lang="en-US">
<Request>
<TransactionReference>
<CustomerContext>Mr UPS</CustomerContext>
<XpciVersion>1.0001</XpciVersion>
</TransactionReference>
<RequestAction>AV</RequestAction>
</Request><address><City>Pottsville</City>
<StateProvinceCode>PA</StateProvinceCode>
</Address>
</AddressValidationRequest>
================================================== ============

========== Exhibit 2 my code snippet =============================================
Expand|Select|Wrap|Line Numbers
  1. Set myHTTP = CreateObject("msxml2.xmlhttp")
  2. Set myDom = CreateObject("MSXML2.DOMDocument")
  3. myDom.async = False
  4. If myDom.loadXML(MYxml) = False Then
  5.     MsgBox "MYxml failed to load"  ' THIS MESSAGE IS BEING DISPLAYED
  6. End If
  7.  
  8. myDom.loadXML (MYxml)  ' load my xml code
  9.  
  10. myHTTP.Open "POST", strUPSWebAddressTest, False
  11. myHTTP.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & strBoundary
  12. myHTTP.setRequestHeader "Content-Disposition", "form-data; name=""xmlmsg"""
  13. myHTTP.setRequestHeader "Content-Length", Len(MYxml)
  14. MsgBox myDom.XML
  15. myHTTP.Send (myDom.XML)
  16. MsgBox myHTTP.responseText
  17. MYResponse = myHTTP.responseText
  18.  
================================================== =================
Exhibit 3: (modified the UPS XML to have 1 top level element)
<?xml version="1.0" encoding="UTF-8"?>
<accessRequest>
<accessLicenseNumber>123abcmyaccesscode</AccessLicenseNumber>
<UserId>xxxxxx</UserId>
<Password>yyyyyy</Password>
<addressValidationRequest xml:lang="en-US">
<Request>
<TransactionReference>
<CustomerContext>Mr UPS</CustomerContext>
<XpciVersion>1.0001</XpciVersion>
</TransactionReference>
<RequestAction>AV</RequestAction>
</Request><address><City>Pottsville</City>
<StateProvinceCode>PA</StateProvinceCode>
</Address>
</AddressValidationRequest>
</AccessRequest>
================================================== ============
May 1 '10 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,221
Okay, I figured it out finally. I changed
myHTTP.Send (myDom.XML)
to
myHTTP.Send (myXML)

Apparently UPS just wants the string of XML command text (even though it is does not really equal a valid XML file). The DOMDocument insists on valid XML XML so it won't even load the improperly formatted UPS command set.

Please chime in if you can add anything helpful about this.

Jim
May 3 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.