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: System.Xml.Serialization
Assembly: System.Xml (in System.Xml.dll)
Example
This code example defines a class named Book, creates an instance of the class, and uses XML serialization to write the instance to an XML file.
Code similar to this is available as an IntelliSense code snippet. In the Code Snippet Manager, it is located in XML. For more information, see Code Snippets.
public class XMLWrite
{ static void Main(string[] args)
{
WriteXML();
} public class Book
{
public String title;
} public static void WriteXML()
{
Book overview = new Book();
overview.title = "Serialization Overview";
System.Xml.Serialization.XmlSerializer writer =
new System.Xml.Serialization.XmlSerializer(typeof(Book)); var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//SerializationOverview.xml";
System.IO.FileStream file = System.IO.File.Create(path); writer.Serialize(file, overview);
file.Close();
}
}
Compiling the Code
The class must have a public constructor without parameters.
Robust Programming
The following conditions may cause an exception:
The class being serialized does not have a public, parameterless constructor.
The file exists and is read-only (IOException).
The path is too long (PathTooLongException).
The disk is full (IOException).
.NET Framework Security
This example creates a new file, if the file does not already exist.
If an application needs to create a file, that application needs Create access for the folder.
If the file already exists, the application needs only Write access, a lesser privilege.
Where possible, it is more secure to create the file during deployment, and only grant Read access to a single file, rather than Create access for a folder.
How to: Write Object Data to an XML File的更多相关文章
- 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 cl ...
- 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 ...
随机推荐
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- short-path problem (Spfa) 分类: ACM TYPE 2014-09-02 00:30 103人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> #include <queue> #i ...
- smaa github iryoku
dx10 demo 这东西我没法跑nsight ...这就坑大了 里面有个 RenderTargetCollection这个东西里面有很多 rendertargets 最让我苦恼的就是 sceneRT ...
- python实现web分页日志查看
当我们维护一个网站时,无论前台还是后台,经常会出现各种个样的问题.有时候问题很难直观的发现,这个时候只能查看各种日志来跟踪问题.但是查看日志有各种个样的问题.首先,要用各种工具登陆到服务器,这个有时候 ...
- [工作积累] Software keyboard not shown on Activity.onCreate
protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setCo ...
- 如何在PL/SQL Developer 中设置 在select时 显示所有的数据
在执行select 时, 总是不显示所有的记录, 要点一下, 下面那个按钮才会显示所有的数据. 解决方法: Tools>Preferences>Window Types>SQ ...
- Sqli-labs less 25a
Less-25a 不同于25关的是sql语句中对于id,没有''的包含,同时没有输出错误项,报错注入不能用.其余基本上和25示例没有差别.此处采取两种方式:延时注入和联合注入. http://127. ...
- chapter 2
1.分片:序列变量,字符串,列表,元组,集合..都可以使用分片来访问指定的数据项,分片三种方式:seq[]访问某个数据项,seq[-1]表示访问序列最后一个数据项,seq[-2]倒数第二个数据项. s ...
- Extjs文本输入域
var form = Ext.create('Ext.form.Panel', { renderTo: Ext.getBody(), frame: tr ...
- 后缀树系列一:概念以及实现原理( the Ukkonen algorithm)
首先说明一下后缀树系列一共会有三篇文章,本文先介绍基本概念以及如何线性时间内构件后缀树,第二篇文章会详细介绍怎么实现后缀树(包含实现代码),第三篇会着重谈一谈后缀树的应用. 本文分为三个部分, 首先介 ...