I don’t use .Net unless I have to, and for this project I have to. I like the PHP way of doing things but, it seems I am stuck with using a Collection of Object‘s to store/retrieve the data I need. I have my Collection loaded with my Objects‘s and the code to iterate through the collection, my problem is I am unable to retrieve the “key” as it would be called in PHP (I believe in this case it is actually the name of the object). Consider the following example:
Dim xDoc As XPathDocument = New XPathDocument(fName)
Dim xNav As XPathNavigator = xDoc.CreateNavigator()
Dim sender As XPathNodeIterator
sender = xNav.Select("/data/sender/val")
While (sender.MoveNext())
SenderInfo.Add(sender.Current.GetAttribute("n", ""), sender.Current.Value)
End While
For Each item As Object In SenderInfo
Dim value As String = item.ToString()
//need to store the key here
Dim key As String = Nothing
Next
As you can see, I am navigating an XML document, and creating an Object with some Key/Value pairs. The Object would look something like this if it were in JSON:
{"name":"John Smith","address1":"123 Anywhere St.","city":"This City","state":"FL"}
When I iterate though the Collection I can only get the value of the object, but I need the Key, in this instance I want “name”,”address1″,”city”,”state” to be stored in a variable for each iteration.
Any ideas? Or am I going about this the wrong way?
Thanks in advance for the help, I am truly stuck on this one!
SenderInfoshould be aDictionary<String,String>. Here‘s the documentation and example code, at the bottom, including VB.NET.