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:

.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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. uiautomatorviewer 报错 Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!

    在进行自动化时经常需要使用到 uiautomatorviewer获取控件的各个属性,然后在脚本中通过各个控件的属性来操作. 如果使用的是uiautomator2的话,一般都是使用weditor这个来查 ...

  5. 【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 ...

  6. 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 ...

  7. [vb.net]XML File Parsing in VB.NET

    Introduction Parsing XML files has always been time consuming and sometimes tricky. .NET framework p ...

  8. error while obtaining ui hierarchy xml file...用 uiautomatorviewer 获取安卓手机软件页面时报错

    Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't ...

  9. 报错: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 ...

随机推荐

  1. 【BZOJ】【1044】【HAOI2008】木棍分割

    二分/DP 真是一道好题! 第一问很简单的二分…… 第二问一开始我想成贪心了,其实应该是DP的= = 然后没有注意……又MLE又TLE的……这题要对DP进行时空两方面的优化!! 题解:(by JoeF ...

  2. max_flow(Edmond_Karp) 分类: ACM TYPE 2014-09-02 10:47 92人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> #include<queue> usi ...

  3. ObjectStore onFetch方法获取记录总数

    转自:http://blog.csdn.net/earthhour/article/details/38686029 ObjectStore onFetch方法获取记录总数 require(['doj ...

  4. 修改MySQL数据库的密码

    通过MySQL命令行,可以修改MySQL数据库的密码,下面就为您详细介绍该MySQL命令行,如果您感兴趣的话,不妨一看. 格式:mysql -u用户名 -p旧密码 password 新密码 1.给ro ...

  5. HDU4512完美队形I && HDU1423 Greatest Common Increasing Subsequence (LCIS)

    填坑的时候又到啦,校赛因为不会LCIS所以吃了大亏,这里要补起来.LCIS就是在两个串里找最长上升子序列,相关的博客有很多,这里自己就不写那么多了. http://www.cnblogs.com/ja ...

  6. DevExpress GridView 自定义搜索按钮改为中文内容

    首先将 GridControl 控件的搜索功能显示出来. http://www.cnblogs.com/DeepLearing/p/3887601.html 显示效果如下: 可以通过 GridLoca ...

  7. DMS平台从.NET 1.1升级到.NET 4.0的升级步骤

    1)复制新增的项目到4.0平台解决方案对应目录,添加到到解决方案中:2)合并公共文件(比如修改了FormMain主界面.基础类库.售后界面的修改)3)控件的修订(Dev少数属性可能需要手工调整为新的方 ...

  8. Android图片缩放方法

    安卓开发中应用到图片的处理时候,我们通常会怎么缩放操作呢,来看下面的两种做法: 方法1:按固定比例进行缩放 在开发一些软件,如新闻客户端,很多时候要显示图片的缩略图,由于手机屏幕限制,一般情况下,我们 ...

  9. JS异步加载的三种方式

    js加载的缺点:加载工具方法没必要阻塞文档,过得js加载会影响页面效率,一旦网速不好,那么整个网站将等待js加载而不进行后续渲染等工作. 有些工具方法需要按需加载,用到再加载,不用不加载,. 默认正常 ...

  10. Jmeter之Bean shell使用(二)

    上一篇Jmeter之Bean shell使用(一)简单介绍了下Jmeter中的Bean shell,本文是对上文的一个补充,主要总结下常用的几种场景和方法,相信这些基本可以涵盖大部分的需求.本节内容如 ...