[VB.Net] XML-auslesen

Maxro

Mitglied
hy leutz ..

Ich Versuche eine Xml-Datei mit folgendem Inhalten (tags) auszulesen :

XML :
HTML:
- <Title>
  <id>01-4_clubbers_feat_silvy_-_time_(the_hitmen_remix).mp3</id> 
  <id>01-apollo_-_dance_2007__megara_vs_dj_lee_remix_---www.technorocker.info.mp3</id> 
  <id>01-bangboy_vs_hansebanger_-_hamburg_city_(club_mix)---www.technorocker.info.mp3</id> 
...
...
..
..
....
<id>[TECHNO HARDCORE] speedcore__style__gabba nation__ron d core__shockwave__strike__DOA mix by dj VAnUX.mp3</id> 
  </Title>


hier mein Code :

Code:
        Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click

        Dim xmlList As New Xml.XmlDocument()
        xmlList.Load("Maxro05.08.2007.xml")
        Dim Id As String
        Id = xmlList.DocumentElement.Name
        Dim anzahl As Integer
        Dim counter As Integer = 0
        anzahl = xmlList.DocumentElement.ChildNodes.Count()

again:  If counter = (anzahl - 1) Then
            Me.ListBox1.Items.Add(xmlList.DocumentElement.ChildNodes(counter).Value)
        Else
            counter += 1
            Me.ListBox1.Items.Add(xmlList.DocumentElement.ChildNodes(counter).Value)
            GoTo again
        End If
    End Sub

Der Code soll mir den Inhalt eines <id>..</id> Tags Liefern und in die ListBox1 schreiben (pro <id> ..</id> ein neuse ListBox Item)

Nur allerdings bekomme ich bei meinem Code Folgenden fehler :

System.ArgumentNullException wurde nicht behandelt.
Message="Der Wert darf nicht NULL sein.
Parametername: item"
ParamName="item"
Source="System.Windows.Forms"
StackTrace:
bei System.Windows.Forms.ListBox.ObjectCollection.AddInternal(Object item)
bei System.Windows.Forms.ListBox.ObjectCollection.Add(Object item)
bei WindowsApplication6.Form1.Button11_Click(Object sender, EventArgs e) in C:\Dokumente und Einstellungen\Maxro\Eigene Dateien\Visual Studio 2005\Projects\WindowsApplication6\WindowsApplication6\Form1.vb:Zeile 201.
bei System.Windows.Forms.Control.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
bei System.Windows.Forms.Button.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.Run(ApplicationContext context)
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
bei WindowsApplication6.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 81.
bei System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()

Ich hoffe jemand kann mir weiterhelfen !
 
Zuletzt bearbeitet:
Mach mal so:
Code:
    Dim doc As New XmlDocument
    doc.Load("Maxro05.08.2007.xml")
    Dim xnlIds As XmlNodeList = doc.SelectNodes("/Title/id")
    If ((Not xnlIds Is Nothing) AndAlso (xnlIds.Count > 0)) Then
        Dim xnId As XmlNode
        For Each xnId In xnlIds
          Me.ListBox1.Items.Add(xnId.InnerText)
        Next
    End If
 
hy danke für deine schnell Antwort ..

Aber ich habe schon eine Lösung trozdem vielen dank ! :)

Ich hab den code umgebaut und es so gemacht :

Code:
        Dim xmlList As New Xml.XmlDocument()
        xmlList.Load(".....\maxro.xml")
        For Each node As Xml.XmlNode In xmlList.DocumentElement.ChildNodes
            Me.ListBox1.Items.Add(node.InnerText)
        Next
 

Neue Beiträge

Zurück