VB.Net XML Parsing Issue



I am having some difficulty parsing some XML information in to a richtextbox. I am pulling an XML file from a stream and the data is coming through successfully but when I try to view the elements I think there is a problem.


Here is a snippet of the stream after it has been loaded(there are usually values next to each form name)


"< form name="SupportRepID">1234< /form>


< form name="SupportRepName">John Smith< /form>


< form name="SupportRepKey">XXXXX-XXXXX-XXXXX-XXXXX-XXXXX< /form>


< form name="DepartmentID">1< /form>


< form name="DepartmentName">General< /form>


< form name="DepartmentCurrency">$< /form>"


My end goal is to be able to grab the SupportRepKey and the SupportRepName.


the problem I think lies with each name under < details > not being classified as an Element. When I run the code like this to try and get the value for "SupportRepKey" the messagebox will show a null value(blank).



Dim reader As XDocument = XDocument.Load(dataStream)



For Each detail As XElement In reader...<details>
Dim APIKey As String = detail.Element("SupportRepKey")
MessageBox.Show(APIKey) 'returns null value
Next


If I run it with this(for troubleshooting to make sure the XML file is being pulled from the dataStream):



Dim reader As XDocument = XDocument.Load(dataStream)

For Each detail As XElement In reader...<details>
MessageBox.Show(detail.Value) 'returns all values in one long string
Next


It returns all the values next to each < form name=""> in one long string: "1234JohnSmithXXXXX-XXXXX-XXXXX-XXXXX-XXXXX1General$"


I am using an API to interact with system where I work. The RepName and RepKey are generated anytime someone enters their log in information and every rep has a seperate key. I need to be able to grab just these two things and set them as variables or as text in a text field so I can further interact with API per user.


I think it has something to do with the objects under < details > being form name="" but I have looked everywhere for the past two days and come to no help. Maybe I'm not searching for the right terms, but I love this site. Everyone is always so helpful so I guess I'll try my luck. Thanks!


No comments:

Post a Comment