How to read an XML File

后端 未结 2 1058
-上瘾入骨i
-上瘾入骨i 2020-12-07 05:28

I have a VB.net program. I\'m attempting to use XMLReader to read a .xml file. I want to break the XML File up to organize it into different \"Sections\" In this example

2条回答
  •  旧巷少年郎
    2020-12-07 06:03

    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

    
    
    
        Form Test
    
    
        Button Test
    
    
    

    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()
    

提交回复
热议问题