0

I'm trying to read a simple xml file value and saving values into arrays. The problem is that it's unable to read the value and there is no logic error.

Code

    'data arrays
        Dim account_ids(0) As Integer
        Dim account_icons(0) As String
        Dim account_names(0) As String
        Dim account_paths(0) As String
    ' load accounts xml
    Dim xmlFilePath As String = "xmlAccountData.xml"
    If My.Computer.FileSystem.FileExists(xmlFilePath) = True Then
        Dim doc As XmlReader = New XmlTextReader(xmlFilePath)
        While (doc.Read())
            Dim type = doc.NodeType
            If (type = XmlNodeType.Element) Then
                If (doc.Name = "accountID") Then
                    Array.Resize(account_ids, account_ids.Length + 1)
                    account_ids(account_ids.Length - 1) = doc.ReadInnerXml.ToString()
                    MsgBox(doc.ReadInnerXml.ToString())
                End If
                If (doc.Name = "iconPath") Then
                    Array.Resize(account_icons, account_icons.Length + 1)
                    account_icons(account_icons.Length - 1) = doc.ReadInnerXml.ToString()
                    MsgBox(doc.ReadInnerXml.ToString())
                End If
                If (doc.Name = "accountName") Then
                    Array.Resize(account_names, account_names.Length + 1)
                    account_names(account_names.Length - 1) = doc.ReadInnerXml.ToString()
                    MsgBox(doc.ReadInnerXml.ToString())
                End If
                If (doc.Name = "accountPath") Then
                    Array.Resize(account_paths, account_paths.Length + 1)
                    account_paths(account_paths.Length - 1) = doc.ReadInnerXml.ToString()
                    MsgBox(doc.ReadInnerXml.ToString())
                End If
            End If
        End While
    End If

Xml file

<?xml version="1.0" standalone="yes"?>
<dsAccounts xmlns="http://tempuri.org/dsAccounts.xsd">
  <dt_Accounts>
    <accountID>0</accountID>
    <iconPath>path\bin\Debug\res\icon.png</iconPath>
    <accountName>asa</accountName>
    <accountPath>accounts\asa</accountPath>
  </dt_Accounts>
  <dt_Accounts>
    <accountID>1</accountID>
    <iconPath>path\bin\Debug\res\imageicon.png</iconPath>
    <accountName>drav</accountName>
    <accountPath>accounts\drav</accountPath>
  </dt_Accounts>
</dsAccounts>

Problem When reading the data, I'm poping up messagebox after each value is read. But the msgbox displays nothing. Same for the arrays, no data saved. It's blank.

Is there anything I'm missing or need to do in order to read the values. The same code in other project works fine.. Thankyou.

1 Answer 1

1
    'data arrays
    Dim account_ids(0) As Integer
    Dim account_icons(0) As String
    Dim account_names(0) As String
    Dim account_paths(0) As String
    ' load accounts xml
    Dim xmlFilePath As String = "xmlAccountData.xml"
    If My.Computer.FileSystem.FileExists(xmlFilePath) = True Then
        Dim doc As XmlReader = New XmlTextReader(xmlFilePath)
        While (doc.Read())
            Dim type = doc.NodeType
            If (type = XmlNodeType.Element) Then
                If (doc.Name = "accountID") Then
                    Array.Resize(account_ids, account_ids.Length + 1)
                    account_ids(account_ids.Length - 1) = doc.ReadElementContentAsInt()
                    MsgBox(account_ids(account_ids.Length - 1).ToString())
                End If
                If (doc.Name = "iconPath") Then
                    Array.Resize(account_icons, account_icons.Length + 1)
                    account_icons(account_icons.Length - 1) = doc.ReadElementContentAsString()
                    MsgBox(account_icons(account_icons.Length - 1))
                End If
                If (doc.Name = "accountName") Then
                    Array.Resize(account_names, account_names.Length + 1)
                    account_names(account_names.Length - 1) = doc.ReadElementContentAsString()
                    MsgBox(account_names(account_names.Length - 1))
                End If
                If (doc.Name = "accountPath") Then
                    Array.Resize(account_paths, account_paths.Length + 1)
                    account_paths(account_paths.Length - 1) = doc.ReadElementContentAsString()
                    MsgBox(account_paths(account_paths.Length - 1))
                End If
            End If
        End While
    End If
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.