[RESOLVED] Help using this code for multiple XDocument nodes
Ok, so I've got this code and it works great with the fact that it does exactly what I want, except for the fact that it'll only work with one node then move where I need it to work with one node then run the check again for any nodes after that one that have the same value in an attribute. The idea behind this is:
the ListItem has an attribute with a program location and what time to start/end the specified program.
Any idea what direction I need to go for this to work through the full document?
vb Code:
Dim iTime As String = hours & ":" & minutes & ap
Try
Dim xml As XDocument = XDocument.Load(xmlDatabase)
Dim e = From element
In xml.Root.Elements("ListItem")
Where (element.Attribute("StartTime").Value = iTime)
Select element
Dim ex As XAttribute = e.Attributes.ElementAt(2)
Dim sTime As String = ex.Value
If iTime.Equals(sTime) Then
Dim ax As XAttribute = e.Attributes.ElementAt(1)
Process.Start(ax.Value)
End If
Catch
End Try
Re: Help using this code for multiple XDocument nodes
Ah, the power of google. So I looked for about an hour before I posted this and kept looking while I waited on an answer. Here is what I found for myself:
vb Code:
Dim xelement As XElement = XElement.Load("..\..\Employees.xml")
Dim employees As IEnumerable(Of XElement) = xelement.Elements()
' Read the entire XML
For Each employee In employees
Console.WriteLine(employee)
Next employee
I managed to adapt it to:
vb Code:
Dim iTime As String = hours & ":" & minutes & ap
Try
Dim xel As XElement = XElement.Load(xmlDatabase)
Dim ListItem As IEnumerable(Of XElement) = xel.Elements()
For Each item In ListItem
If item.ToString.StartsWith("<ListItem") Then
If iTime.Equals(item.Attribute("StartTime").Value) Then
Dim ax As XAttribute = item.Attributes.ElementAt(1)
Process.Start(ax.Value)
End If
End If
Next
Catch ex As Exception
End Try
And that seems to be doing exactly what I need it to. Thanks for the help google :D