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 ...
随机推荐
- Leetcode#129 Sum Root to Leaf Numbers
原题地址 二叉树的遍历 代码: vector<int> path; int sumNumbers(TreeNode *root) { if (!root) ; ; path.push_ba ...
- A*(A星)算法python实现
在春节放假前两天我偶然看到了A\*算法(A\*算法是一个启发式的地图寻路算法),感觉挺有意思.正好放假前也没有什么事情,就花了一个下午写出算法的骨架,节后又花了半天时间完善屏幕输出的细节并且调试完成. ...
- C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(611,5): error MSB
project options, linker, manifest, Generate Manifest-> NO. 项目->属性->链接器->清单文件->生成清单 改 ...
- [工作积累] JNI native 函数签名
对于一个Java 类 class MyClass { ... public native boolean nativeMyFunc(long param); } 一般来说native对应的声明是这样: ...
- PHP一些函数
函数不定参数: func_num_args // 获得参数个数 func_get_args // 获得参数数组 call_user_func('function_name', $parameter) ...
- 我是如何学习 Linux 的
为何要学习 Linux? 这个问题可能困扰着很多 Linux 初学者和爱好者,其实我也说不上来为何要学习 Linux,可能最实在的理由就是—-Linux 相关工作岗位很多.在“见到” Linux 的第 ...
- lintcode : 跳跃游戏
跳跃游戏 给出一个非负整数数组,你最初定位在数组的第一个位置. 数组中的每个元素代表你在那个位置可以跳跃的最大长度. 判断你是否能到达数组的最后一个位置. 样例 A = [2,3,1,1,4],返回 ...
- Android 核心分析 之五基本空间划分
基本空间划分 Google给了我们一张系统架构图,在这张图上我们可以看到Android的大体框架组成. 11.jpg (175.6 KB, 下载次数: 0) 下载附 ...
- iOS开发--Bison详解连连支付集成简书
"最近由于公司项目需要集成连连支付,文档写的不是很清楚,遇到了一些坑,因此记录一下,希望能帮到有需要的人." 前面简单的集成没有遇到什么坑,在此整理一下官方的集成文档,具体步骤如下 ...
- VCL定义和使用CM_Message的原因(主要是内部控制,同时可简化参数传递,还可截住消息,统一走消息路线,还可省内存)
内部控制是指,做了某些操作后产生某些效果,但是Windows系统本身不提供这样的消息,应此不得不自定义.比如父窗口改变了字体,那么所有子窗口也都应该改变字体,至少也得通知一下它们,让子控件自己决定是否 ...