Not reading all XML file...

lidds

Well-known member
Joined
Oct 19, 2004
Messages
122
Programming Experience
Beginner
I have an XML file, shown below:

VB.NET:
<?xml version="1.0" standalone="no"?>
<!--RISInsight server settings-->
<Configuration>
  <Server>
    <ConnectionMode>ServerName</ConnectionMode>
    <ServerName>(local)</ServerName>
    <IPAddress>NR</IPAddress>
    <IPPort>NR</IPPort>
    <SMTPServer></SMTPServer>
    <SMTPPort></SMTPPort>
    <SMTPUserName></SMTPUserName>
    <SMTPPassword></SMTPPassword>
    <LicenseFile>C:\Program Files\Ticodi\ReviewInsight\License\ReviewInsight.lic</LicenseFile>
  </Server>
  <Server>
    <ConnectionMode>ServerName</ConnectionMode>
    <ServerName>(local)</ServerName>
    <IPAddress>NR</IPAddress>
    <IPPort>NR</IPPort>
    <SMTPServer></SMTPServer>
    <SMTPPort></SMTPPort>
    <SMTPUserName></SMTPUserName>
    <SMTPPassword></SMTPPassword>
    <LicenseFile>C:\Program Files\Ticodi\ReviewInsight\License\ReviewInsight.lic</LicenseFile>
  </Server>
</Configuration>

The problem is that I want to read the complete XML file, however because I am repeating the same XMLElementName it only seems to read the first element, the code I am using is the following:

VB.NET:
        Dim reader As Xml.XmlTextReader = New Xml.XmlTextReader(Application.StartupPath & "\settings.ini")
        Do While (reader.Read())
            Dim addToList As Boolean = False
            Select Case reader.NodeType
                Case Xml.XmlNodeType.Element
                    xmlElementName = reader.Name
                Case Xml.XmlNodeType.Text
                    If xmlElementName = "ConnectionMode" Then
                        RISData.Instance.ConnectionMode = reader.Value
                    ElseIf xmlElementName = "IPAddress" Then
                        RISData.Instance.IPAddress = reader.Value
                    ElseIf xmlElementName = "IPPort" Then
                        RISData.Instance.IPPort = reader.Value
                        addToList = True
                    ElseIf xmlElementName = "ServerName" Then
                        RISData.Instance.ServerName = reader.Value
                    ElseIf xmlElementName = "LicenseFile" Then
                        RISData.Instance.LicenseLocation = reader.Value
                    ElseIf xmlElementName = "SMTPServer" Then
                        RISData.Instance.SMTPServer = reader.Value                        
                    ElseIf xmlElementName = "SMTPPort" Then
                        RISData.Instance.SMTPPort = reader.Value
                    ElseIf xmlElementName = "SMTPUserName" Then
                        RISData.Instance.SMTPUserName = reader.Value
                    ElseIf xmlElementName = "SMTPPassword" Then
                        RISData.Instance.SMTPPassword = reader.Value
                    End If

                    If addToList = True Then
                        Me.lstServer.BeginInit()

                        If RISData.Instance.ConnectionMode = "ServerName" Then
                            Dim data As Object() = New Object() {RISData.Instance.ServerName, "N/A"}
                            Me.lstServer.Rows.Items.Add(New Node(data))
                        Else
                            Dim data As Object() = New Object() {RISData.Instance.IPAddress, RISData.Instance.IPPort}
                            Me.lstServer.Rows.Items.Add(New Node(data))
                        End If

                        Me.lstServer.EndInit()
                        addToList = False
                    End If
            End Select
        Loop
        reader.Close()

Is there a way that I can make it continue to read the XML file?

Thanks in advance

Simon
 
Multiple loops and send the InnerText for each loop where you want it.

VB.NET:
Dim xl As New XmlDocument(path)
xl.Load
Dim rootnode As Xmlnode = xl.SelectSingleNode("Configuration") 
For Each cldnode As XmlNode In rootnode.childnodes
    'this will return 2 server elements loop again thru these
     For Each node As XmlNode In cldnode.childnodes
         Textbox1.Text &= node.InnerText
     Next
Next
I hope the syntsx is correct, I am iTouching. ;)
 
Back
Top