How to: Read Object Data from an XML File
This example reads object data that was previously written to an XML file using the XmlSerializer class.
Example
This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in XML. For more information, see Code Snippets.
public class Book
{
public String title;
} public void ReadXML()
{
// First write something so that there is something to read ...
var b = new Book { title = "Serialization Overview" };
var writer = new System.Xml.Serialization.XmlSerializer(typeof(Book));
var wfile = new System.IO.StreamWriter(@"c:\temp\SerializationOverview.xml");
writer.Serialize(wfile, b);
wfile.Close(); // Now we can read the serialized book ...
System.Xml.Serialization.XmlSerializer reader =
new System.Xml.Serialization.XmlSerializer(typeof(Book));
System.IO.StreamReader file = new System.IO.StreamReader(
@"c:\temp\SerializationOverview.xml");
Book overview = (Book)reader.Deserialize(file);
file.Close(); Console.WriteLine(overview.title); }
Compiling the Code
Replace the file name "c:\IntroToVB.xml" with the name of the file containing the serialized data. For more information about serializing data, see How to: Write Object Data to an XML File (C# and Visual Basic).
The class must have a public constructor without parameters.
Only public properties and fields are deserialized.
Robust Programming
The following conditions may cause an exception:
The class being serialized does not have a public, parameterless constructor.
The data in the file does not represent data from the class to be deserialized.
The file does not exist (IOException).
.NET Framework Security
Always verify inputs, and never deserialize data from an untrusted source.
The re-created object runs on a local computer with the permissions of the code that deserialized it.
Verify all inputs before using the data in your application.
How to: Read Object Data from an XML File的更多相关文章
- How to: Write Object Data to an XML File
This example writes the object from a class to an XML file using the XmlSerializer class. Namespace: ...
- RCE via XStream object deserialization && SECURITY-247 / CVE-2016-0792 XML reconstruction Object Code Inject
catalogue . Java xStream . DynamicProxyConverter . java.beans.EventHandler . RCE via XStream object ...
- uiautomator:Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!
尝试用android sdk的uiautomatorviewer抓元素的时候报错:Error while obtaining UI hierarchy XML file: com.android.dd ...
- uiautomatorviewer 报错 Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!
在进行自动化时经常需要使用到 uiautomatorviewer获取控件的各个属性,然后在脚本中通过各个控件的属性来操作. 如果使用的是uiautomator2的话,一般都是使用weditor这个来查 ...
- 【Android】【问题解决记录】Error obtaining UI hierarchy :Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!
在使用uiautomatorviewer时遇到两类Error obtaining UI hierarchy报错,分别是: Error while obtaining UI hierarchy XML ...
- Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't
在使用真机定位页面元素时启动uiautomatorviewer.bat ,报错Error while obtaining UI hierarchy XML file: com.android.ddml ...
- [vb.net]XML File Parsing in VB.NET
Introduction Parsing XML files has always been time consuming and sometimes tricky. .NET framework p ...
- error while obtaining ui hierarchy xml file...用 uiautomatorviewer 获取安卓手机软件页面时报错
Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't ...
- 报错:Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
近期学习RecyclerView,使用eclipse引用RecyclerView.编写完demo后编译没有问题,一执行就挂掉,错误例如以下: 07-22 23:05:34.553: D/Android ...
随机推荐
- hdu 2853 Assignment KM算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2853 Last year a terrible earthquake attacked Sichuan ...
- ToolStripButton样式
public static class Extensions { public static void SetMouseDownStyle(this ToolStripButton button) { ...
- 【bzoj1011】[HNOI2008]遥远的行星
1011: [HNOI2008]遥远的行星 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 3711 Solved ...
- Linux --windows vs
我其实并不是很清楚我在做什么....希望做完之后可以解答....... 在看了一堆GNU, Clang, GCC, QT, MinGW, CygWin, POSIX 这些概念之后,我觉得我在做的事情就 ...
- TLS学习总结
我们有知道 Immunity Debugger,OD 调试器,在调试程序时会设断在OEP(修改第一个字节0xcc).我在想,使用什么编程技术,代码可以在OEP前被执行.在网上找了些资料,在论坛上看到许 ...
- PE文件结构学习
PE:Portable Executable File Format(可移植的执行体).Windows平台主流可执行文件格式..exe与.dll文件都是PE格式.32位的叫做PE32,64位的叫做PE ...
- 如何创建和发布.asmx Web Service
创建和发布Web ServiceWeb服务方法中可以返回一个DataSet对象 WEB服务可以说是下一代WEB应用程序的基础,无论客户端是WINDOWS应用.ASP.NET Web Form程序.甚至 ...
- (翻译)Google Guava Cache
翻译自Google Guava Cache This Post is a continuation of my series on Google Guava, this time covering G ...
- tar命令--解压缩
tar命令是linux中的一个解压缩的命令.使用tar命令之前首先要搞清楚两个概念:打包和压缩.打包是指将一大堆文件或目录变成一个总的文件:压缩则是将一个大的文件通过一些压缩算法变成一个小文件. 为什 ...
- Ruby Profiler 详解之 ruby-prof(I)
项目地址: ruby-prof 在上一篇 Ruby 中的 Profiling 工具中,我们列举了几种最常用的 Profiler,不过只是简单介绍,这一次详细介绍一下 ruby-prof 的使用方法. ...