我有一个 VB.net 程序。我正在尝试使用 XMLReader 读取 .xml 文件。我想分解 XML 文件以将其组织成不同的“部分”在这个例子中"FormTitle"
和"ButtonTitle"
. 我想从中获取<Text>
数据FormTitle
并将其显示为表单"text"
,然后将其显示<Text>
在"ButtonTitle"
按钮文本中。
这是我的 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<!--XML Database.-->
<FormTitle>
<Text>Form Test</Text>
</FormTitle>
<ButtonTitle>
<Text>Button Test</Text>
</ButtonTitle>
这是我当前的代码:
If (IO.File.Exists("C:\testing.xml")) Then
Dim document As XmlReader = New XmlTextReader("C:\testing.xml")
While (document.Read())
Dim type = document.NodeType
If (type = XmlNodeType.Element) Then
'
If (document.Name = "Text") Then
Me.Text = document.ReadInnerXml.ToString()
End If
End If
End While
Else
MessageBox.Show("The filename you selected was not found.")
End If
怎么能带入下一段(ButtonTitle)
同名即在FormTitle
哪是(Text)
。我会假设我需要在 if then 语句中引用FormTitle
和?ButtonTitle