how to step through xml elements with the same name



Ok, so this is my second post on here and I am getting hung up with working with XML within vb.net, still.


I know how to grab the data I need for single elements with unique names, but what about if that process repeats?


My example, I am using an API to interact with a program at work. When I use the API to run a search for tickets related to a store # it returns multiple values like this:



<requests>
<request>
<form name="requestID">999999</form>
<form name="userTimeFormat">EEE, MMM d HH:mm:ss z yyyy</form>
<form name="contact">Contact Name</form>
<form name="status">Status</form>
<form name="statusID"></form>
<form name="priority"></form>
<form name="supportRep">Tom Smith</form>
<form name="supportRepCostPerHour">0.00</form>
<form name="createdTime">Time/Date</form>
<form name="updatedTime">Time/Date</form>
<form name="dueByTime">Time/Date</form>
<form name="isOverDue">T/F</form>
<form name="accountID"/>
<form name="account"/>
<form name="subject">Subject Goes Here</form>
</request>

<request>
<form name="requestID">999998</form>
<form name="userTimeFormat">EEE, MMM d HH:mm:ss z yyyy</form>
<form name="contact">Contact Name</form>
<form name="status">Status</form>
<form name="statusID"></form>
<form name="priority"></form>
<form name="supportRep">Tom Smith</form>
<form name="supportRepCostPerHour">0.00</form>
<form name="createdTime">Time/Date</form>
<form name="updatedTime">Time/Date</form>
<form name="dueByTime">Time/Date</form>
<form name="isOverDue">T/F</form>
<form name="accountID"/>
<form name="account"/>
<form name="subject"> Subject Goes Here </form>
</request>


So when I use XPath to grab information it works perfectly for the first < request > but my question is how do I move to the next < request > to get the next set of data?


here is my code that grabs it:



For Each requests As XElement In reader...<request>
Dim ReqID As String = reader.XPathSelectElement("//form[@name='requestID']")
Dim contact As String = reader.XPathSelectElement("//form[@name='contact']")


I know I need some sort of loop to to repeat the process but right now I'm at a loss. Any and all help/comments are appreciated. I am new to coding and vb, but I am a quick and eager learner. Thanks.


No comments:

Post a Comment