您的位置:首页 > 其它

如何:从 XML 文件中读取类数据

2013-04-13 20:22 316 查看
此示例使用 XmlSerializer类的 Deserialize 方法读取存储在名为 IntroToVCS.xml 的示例文件中的对象上的数据。

public class Book
{
public string title;

static void Main()
{
Book introToVCS  = new Book();
System.Xml.Serialization.XmlSerializer reader = new
System.Xml.Serialization.XmlSerializer(introToVCS.GetType());

// Read the XML file.
System.IO.StreamReader file=
new System.IO.StreamReader("c:\\IntroToVCS.xml");

// Deserialize the content of the file into a Book object.
introToVCS = (Book) reader.Deserialize(file);
System.Windows.Forms.MessageBox.Show(introToVCS.title,
"Book Title");
}
}


以下条件可能会导致异常:

路径名可能太长。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐