XML Richtig auswerten

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von TheSCHFan#.

    XML Richtig auswerten

    Hallo!
    Ich wollte fragen wie ich diese XML Datei:

    XML-Quellcode

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <!--XML Database.-->
    3. <Data>
    4. <Sponge>
    5. <Name>Sponge</Name>
    6. <Download>OFF</Download>
    7. <Version>OFF</Version>
    8. </Sponge>
    9. <Bukkit>
    10. <Name>Bukkit</Name>
    11. <Download>DMCA</Download>
    12. <Version>DMCA</Version>
    13. </Bukkit>
    14. </Data>


    So auswerten kann dass in einer Listbox das hier steht:

    Quellcode

    1. Sponge
    2. Bukkit


    und wenn man dann das ausgewählte Item anklickt dass ich ein DLLink Returnt bekomme (Bei der XML Datei das was bei <Download> steht)

    Spoiler anzeigen

    Visual Basic-Quellcode

    1. Private Sub ReadIndex()
    2. 'check if file myxml.xml is existing
    3. If (IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\Easy Bukkit\servers.xml")) Then
    4. 'create a new xmltextreader object
    5. 'this is the object that we will loop and will be used to read the xml file
    6. Dim document As XmlReader = New XmlTextReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\Easy Bukkit\servers.xml")
    7. 'loop through the xml file
    8. While (document.Read())
    9. Dim type = document.NodeType
    10. 'if node type was element
    11. If (type = XmlNodeType.Element) Then
    12. 'if the loop found a <FirstName> tag
    13. If (document.Name = "Name") Then
    14. ListBox3.Items.Add(document.ReadInnerXml.ToString())
    15. End If
    16. 'if the loop found a <LastName tag
    17. If (document.Name = "LastName") Then
    18. MsgBox(document.ReadInnerXml.ToString())
    19. End If
    20. End If
    21. End While
    22. Else
    23. MessageBox.Show("The filename you selected was not found.")
    24. End If
    25. End Sub
    26. Private Function ReadIndexDL() As String
    27. 'check if file myxml.xml is existing
    28. If (IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\Easy Bukkit\servers.xml")) Then
    29. 'create a new xmltextreader object
    30. 'this is the object that we will loop and will be used to read the xml file
    31. Dim document As XmlReader = New XmlTextReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\Easy Bukkit\servers.xml")
    32. 'loop through the xml file
    33. While (document.Read())
    34. Dim type = document.NodeType
    35. 'if node type was element
    36. If (type = XmlNodeType.Element) Then
    37. 'if the loop found a <FirstName> tag
    38. If (document.Name = "Download") Then
    39. Return document.ReadInnerXml.ToString
    40. End If
    41. End If
    42. End While
    43. Else
    44. Return "OFF"
    45. End If
    46. Return "OFF"
    47. End Function


    EDIT:
    Spoiler anzeigen

    Visual Basic-Quellcode

    1. Private Function ReadIndexDL(ByVal item As String) As String
    2. 'check if file myxml.xml is existing
    3. If (IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\Easy Bukkit\servers.xml")) Then
    4. 'create a new xmltextreader object
    5. 'this is the object that we will loop and will be used to read the xml file
    6. Dim document As XmlReader = New XmlTextReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\Easy Bukkit\servers.xml")
    7. 'loop through the xml file
    8. While (document.Read())
    9. Dim type = document.NodeType
    10. 'if node type was element
    11. If (type = XmlNodeType.Element) Then
    12. If document.Name = item Then
    13. If (document.Name = "Download") Then
    14. Return document.ReadInnerXml.ToString
    15. End If
    16. End If
    17. End If
    18. End While
    19. Else
    20. Return "OFF"
    21. End If
    22. Return "OFF"
    23. End Function​
    Gin auch nicht :(

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „TheSCHFan#“ ()

    Danke für den Tipp!

    Eine Frage zu XDocuments: Wie kann ich eine Variable in die Abfrage packen?

    Visual Basic-Quellcode

    1. Dim XDoc As XDocument = XDocument.Load(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\Easy Bukkit\servers.xml")
    2. Return XDoc.<Data>.<VARIABLE>.<Download>.ToString


    Hat sich Erledigt

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „TheSCHFan#“ ()