Public Class Form1
' Let the user select an XML file.
Private Sub btnSelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFile.Click
If dlgXmlFile.ShowDialog() = Windows.Forms.DialogResult.OK Then
txtFile.Text = dlgXmlFile.FileName
End If
End Sub
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
' Load and parse the XML file.
Dim root_node As DocNode = ParseXmlDocument(txtFile.Text)
' Sort the nodes' children.
root_node.SortChildren()
' Display the result.
txtResults.Text = root_node.PrefixOrder()
End Sub
' Parse the XML document.
Private Function ParseXmlDocument(ByVal file_name As String) As DocNode
' Load the XML file.
Dim xml_doc As New XmlDocument()
xml_doc.Load(file_name)
' Find the <assembly> node.
Dim assembly_node As XmlNode = xml_doc.DocumentElement.Item("assembly")
' Get the <name> value.
Dim root As New DocNode(assembly_node, assembly_node.Item("name").InnerText.Trim, "A")
' Add the <members> to the root node.
Dim members_node As XmlNode = xml_doc.DocumentElement.Item("members")
For Each member As XmlNode In members_node.ChildNodes
' Make the child node.
Dim full_name As String = member.Attributes("name").Value
Debug.Assert(full_name.Contains(":"), "Member node's name does not contain ':'")
Dim type_code As String = full_name.Substring(0, full_name.IndexOf(":"))
full_name = full_name.Substring(full_name.IndexOf(":") + 1)
Dim child_node As New DocNode(member, full_name, type_code)
' Add the child to the root node.
root.AddChild(child_node)
Next member
ini有规范的,有专门的函数可以读取,很方便的,不用像读TXT文本文件那样判断的。给你个可用的例子。
声明
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
代码
dim xuhao as string
xuhao=space(255)
GetPrivateProfileString "load", "an", "没有配置", xuhao, 255, App.Path & "\Style.ini"
msgbox xuhao