Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-11-09
6
Medium Priority
?
1,017 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
 

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

885 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