Solved

How to parse XML address verification response from USPS in VB.NET?

Posted on 2010-11-09
6
952 Views
Last Modified: 2012-06-21
I have successfully sent and received an address validation request to and from USPS.  The response comes back as an XML string, as it should.

Is there some code, wrapper, module, etc. out there that will parse the response elements so that I can easily retrieve street, city, state, zip, etc.?
0
Comment
Question by:mdreed
  • 3
  • 3
6 Comments
 
LVL 17

Expert Comment

by:sweetfa2
ID: 34096771
0
 

Author Comment

by:mdreed
ID: 34102952
The examples, although staightforward, seem to require an XML file path.  I already have the USPS XML string (file contents) in a variable.  How can I use the examples with my variable contents instead of a file path?
Thanks.
0
 
LVL 17

Expert Comment

by:sweetfa2
ID: 34185887
http://msdn.microsoft.com/en-us/library/1af7xa52.aspx

XMLTextReader can take a file as input, or a STRING.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:mdreed
ID: 34190652
I have read the link you provided, but it appears to me that XMLTextReader expects a file name (file path) and not a string variable.

What I have been working with is the following, but I need to parse the XML contents of a string variable instead of an XML file ("H:\Sample.xml").

Dim xDoc As XmlDocument = New XmlDocument()
xDoc.Load("H:\Sample.xml")
Dim Address1 As XmlNodeList = xDoc.GetElementsByTagName("Address1")
Dim Address2 As XmlNodeList = xDoc.GetElementsByTagName("Address2")
Dim City1 As XmlNodeList = xDoc.GetElementsByTagName("City")
Dim ST1 As XmlNodeList = xDoc.GetElementsByTagName("State")
Dim Zip1 As XmlNodeList = xDoc.GetElementsByTagName("Zip5")
Dim Zip2 As XmlNodeList = xDoc.GetElementsByTagName("Zip4")
MessageBox.Show(Address2(0).InnerText & Constants.vbLf & _
                        City1(0).InnerText & ", " & ST1(0).InnerText & " " & _                       Zip1(0).InnerText & "-" & Zip2(0).InnerText)

This code works great, but it won't handle a string variable instead of a file name.  I can change it to use the XMLTextReader, but I don't see how it would work either.  Can you provide and example of how to do as I have done above but with XMLTextReader.
0
 
LVL 17

Accepted Solution

by:
sweetfa2 earned 500 total points
ID: 34191293
XmlTextReader reader = new XmlTextReader(new StringReader(xmlData));
0
 

Author Closing Comment

by:mdreed
ID: 34196688
Works very well with the code I am using to extract the nodes.  Thanks.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now