Results 1 to 2 of 2

Thread: [RESOLVED] [2008] Problem with Nested or Multidimensional Data Structures

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    6

    Resolved [RESOLVED] [2008] Problem with Nested or Multidimensional Data Structures

    Hello,

    Right now I'm working on parsing an XML file and storing the data I need into some form of data structure to be used in by VB.net program. Here's my code:

    Code:
    Imports System.ComponentModel
    Imports System.Xml
    
    
    Public Class getPackageDataForm
        Public defaultQueue As Queue(Of String())
        Public otherQueue As Queue(Of String())
        Public linksQueue As Queue(Of String())
    
        Private cancelled As Boolean
    
        Private Sub xmlProcess_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            BackgroundWorker1.RunWorkerAsync()
        End Sub
    
        Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
            BackgroundWorker1.ReportProgress(0, "(1/3) Loading XML")
            Dim reader As XmlTextReader = New XmlTextReader( (this is where I put my xml URL) )
    
            BackgroundWorker1.ReportProgress(0, "(2/3) Parsing XML")
    
            Dim defaultBoolean As Boolean = False
            Dim otherBoolean As Boolean = False
            Dim linksBoolean As Boolean = False
    
            While (reader.Read())
                Select Case reader.NodeType
                    Case XmlNodeType.Element
                        If reader.Name = "default" Then
                            defaultBoolean = True
                        ElseIf reader.Name = "other" Then
                            otherBoolean = True
                        ElseIf reader.Name = "links" Then
                            linksBoolean = True
                        ElseIf reader.Name = "package" Then
                            If defaultBoolean Then
                                Dim stringData As String() = {reader.GetAttribute("id"), reader.GetAttribute("title"), reader.GetAttribute("filename")}
                                defaultQueue.Enqueue(stringData)
    
                            ElseIf otherBoolean Then
                                Dim stringData As String() = {reader.GetAttribute("id"), reader.GetAttribute("title"), reader.GetAttribute("filename")}
                                otherQueue.Enqueue(stringData)
    
                            ElseIf linksBoolean Then
                                Dim stringData As String() = {reader.GetAttribute("title"), reader.GetAttribute("link")}
                                linksQueue.Enqueue(stringData)
                            End If
                        End If
                    Case XmlNodeType.EndElement
                        If reader.Name = "default" Then
                            defaultBoolean = False
                        ElseIf reader.Name = "other" Then
                            otherBoolean = False
                        ElseIf reader.Name = "links" Then
                            linksBoolean = False
                        End If
                End Select
            End While
        End Sub
    
        Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
    
            packageProgress.Value = e.ProgressPercentage
            statusText.Text = DirectCast(e.UserState, String)
        End Sub
    
        Private Sub cancelDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelProcess.Click
            Me.BackgroundWorker1.CancelAsync()
        End Sub
    End Class
    This snippet is throwing a NullReferenceException.

    Code:
    Dim stringData As String() = {reader.GetAttribute("id"), reader.GetAttribute("title"), reader.GetAttribute("filename")}
    defaultQueue.Enqueue(stringData)
    My suspicion is that I do not grasp how to pass arrays, queues, or any objects as contents of a queue element. Thanks for you help in advance!

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    6

    Re: [2008] Problem with Nested or Multidimensional Data Structures

    Anyone?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width