Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-11-09
6
Medium Priority
?
1,005 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

 

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

662 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