Dim doc As XDocument = XDocument.Load("Database.xml") Dim games As IEnumerable(Of XElement) = From g In doc.Descendants("Game") For Each game As XElement In games Debug.Print("------------") Debug.Print("name= " & game.Attribute(game.FirstAttribute.NextAttribute.Name).Value) 'puisque tu n'as que 2 nodes on prend le premier node... Dim first As XElement = DirectCast(game.FirstNode, XElement) 'ici ce sera location_path Debug.Print(first.Name.ToString & ":") '(en plus il n'y a que 2 attributs) Debug.Print("environement_var= " & first.FirstAttribute.Value) Debug.Print("path= " & first.LastAttribute.Value) '...puis le dernier node Dim last As XElement = DirectCast(game.LastNode, XElement) 'ici ce sera storage Debug.Print(last.Name.ToString & ":") Debug.Print("environement_var= " & last.FirstAttribute.Value) Debug.Print("path= " & last.LastAttribute.Value) Next
Private Sub GetListButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetListButton.Click Dim doc As XDocument = XDocument.Load(Application.startuppath & "\XMLDatabase.xml") Dim games = From g In doc.Descendants("Games") Select New With { .name = g.Descendants("Game").Value, .path = g.Descendants("location_path").Value, .storage = g.Descendants("storage").Value } For Each strings In games ListBoxGames.Items.Add(doc.Document) Next End Sub
<?xml version="1.0" encoding="utf-8" ?> <Games> <Game title="123KickIt" name="1...2...3...KICK IT!"> <location_path environment_variable="%LOCALAPPDATA%" path="\123KickIt"/> <storage environment_variable="%STORAGE%" path="\123KickIt"/> </Game> <Game title="AaaaaRecklessDisregard" name="AaaaaRecklessDisregard"> <location_path environment_variable="%LOCALAPPDATA%" path="\AaaaaRecklessDisregard"/> <storage environment_variable="%STORAGE%" path="\AaaaaRecklessDisregard"/> </Game> </Games>
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim doc As XDocument = XDocument.Load("XMLDatabase.xml") Dim games As IEnumerable(Of XElement) = From g In doc.Descendants("Game") For Each game As XElement In games 'firstattribute est 'title' et firstattribute.nextattribute est 'name' ListBoxGames.Items.Add(game.Attribute(game.FirstAttribute.NextAttribute.Name).Value) Next
Private Function Update_Path(path As String) As String path = Replace(path, "%STORAGE%", TextBox0.Text & "\Games") path = Replace(path, "%LOCALAPPDATA%", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)) Return path End Function
Dim doc As XDocument = XDocument.Load("Database.xml") Dim games As IEnumerable(Of XElement) = From g In doc.Descendants("Game") For Each game As XElement In games MsgBox(game.Attribute(game.FirstAttribute.NextAttribute.Name).Value) If System.IO.Directory.Exists(game.Attribute(game.FirstAttribute.NextAttribute.Name).Value) Then ListBoxGames.Items.Add(game.Attribute(game.FirstAttribute.NextAttribute.Name).Value) End If Next
Dim doc As XDocument = XDocument.Load("Database.xml") Dim games As IEnumerable(Of XElement) = From g In doc.Descendants("Game") For Each game As XElement In games Dim first As XElement = DirectCast(game.FirstNode, XElement) Dim last As XElement = DirectCast(game.LastNode, XElement) If System.IO.Directory.Exists(Update_Path(first.FirstAttribute.Value) & first.LastAttribute.Value) Then ListBoxGames.Items.Add(game.Attribute(game.FirstAttribute.NextAttribute.Name).Value) End If