Parsing XML data in C# and show into ListBox

前端 未结 4 2072
灰色年华
灰色年华 2020-12-11 08:36

I am trying to parse a XML file in C# using Visual Studio and show the data in a ListBox, but I don\'t know how to parse it when I\'m dealing with a nested XML file.

4条回答
  •  春和景丽
    2020-12-11 08:38

    XmlSerializer mySerializer = new XmlSerializer(typeof(Persons));
    // Create a FileStream or textreader to read the xml data.
    FileStream myFileStream = new FileStream("xmldatafile.xml", FileMode.Open);
    
    var person = (Persons)  mySerializer.Deserialize(myFileStream);
    

    You also need to add constructor without parameter for Persons class.

提交回复
热议问题