How to read an XML File

我是研究僧i 提交于 2019-11-28 02:23:14

Check out this example. http://msdn.microsoft.com/en-us/library/dc0c9ekk.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2

You should can use:

doc.GetElementsByTagName("FormTitle")

You can then loop through all of the child nodes. http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.childnodes.aspx

    Dim root As XmlNode = doc.GetElementsByTagName("FormTitle").Item(1)

    'Display the contents of the child nodes. 
    If root.HasChildNodes Then 
        Dim i As Integer 
        For i = 0 To root.ChildNodes.Count - 1
            Console.WriteLine(root.ChildNodes(i).InnerText)
        Next i
    End If 

Using XDocument is more efficient for reading Xml and also more readable due to less syntax.

You need to add a root to your XML. I called it root, but it can be anything. It just encapsultes all of your XML

<?xml version="1.0" encoding="utf-8"?>
<root>
<FormTitle>
    <Text>Form Test</Text>
</FormTitle>
<ButtonTitle>
    <Text>Button Test</Text>
</ButtonTitle>
</root>

Here is an example of pulling the "Form Test" from FormTitle

    Dim document As XDocument = XDocument.Load("c:\tmp\test.xml")
    Dim title = From t In document.Descendants("FormTitle") Select t.Value

assign text to form

Form1.Text = title.First()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!