vb.net 以读文本文件的方式对XML文件进行遍历

'    对XML文件按照文本文件的方式进行遍历

Private Sub checkFile_establishEntity(strFile As String)

       Dim reader AsTextReader = File.OpenText(strFile)    '  打开文件

       Dim ii AsInteger = 0   ' 行号

       Dim line AsString = reader.ReadLine()    '  读第一行

              While line <> ""

                       ii += 1          '   当前行号

                   'MessageBox.Show(line)      '    Line     <RICD>C10782999</RICD>

                      Dim strs AsString() = line.Split(">")

                      ' 假设输入的line为   <RICD>C10782999</RICD>

                      '                   <RICD   >    C10782999</RICD   >

                      '    拆分以后得到:  "<RICD",  "C10782999</RICD" , "" 

                    '                      0          1                2      ,  共3个字符串

                     If strs.Length > 2 Then    '  如果有两个以上字符串

                                '  说明这一行里边是有内容的,至少是类似于:    <RICD></RICD>   

                           ' MessageBox.Show(strs(0).Split("<")(1) & " --- " & strs(1).Split("</")(0))

                              Dim strName AsString = strs(0).Split("<")(1).Split(" ")(0)     '  取得元素名:    RICD

                              Dim strValue AsString = strs(1).Split("</")(0)             '  取得元素值: C10782999  

                              'MessageBox.Show(strName & " --- " & strValue)

                              '     注意:    元素值可能是空的

                    End If

                                  line = reader.ReadLine       ' 再读一行

        End While

        reader.Close()

       'MessageBox.Show(" checkFile1 OK,  该文件共有 " & ii & " 行")

 

End Sub

猜你喜欢

转载自www.cnblogs.com/gaoleionline/p/11739319.html