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 ...
随机推荐
- lua与 object-C 通信
IOS中如何调用LUA,以及LUA如何调用IOS中的功能 下面将讲解一下如何在iOS里调用Lua函数,以及Lua函数如何调用iOS本地函数. 转载请注明出处.原文出处 http://www.cnblo ...
- c++ union
什么是union? 翻译过来说,就是共用体,或者也叫联合体.说到了union,也就是共用体,就不得不说一下struct了,当我们有如下的struct的定义时: 1 2 3 4 5 6 struct ...
- 9 I/O复用
I/O复用使得程序能够同时监听多个文件描述符,适用于以下情况: 客户端同时处理多个socket,比如非阻塞connect 客户端同时处理用户输入和网络连接,比如聊天室程序 TCP服务器同时处理监听so ...
- linux用户配置和用户权限
一.查看用户: (1)在终端里.输入:cat /etc/passwd,查看/etc/passwd文件就行了.(2)看第三个参数:500以上的,就是后面建的用户了.其它则为系统的用户. 查看当前在线用户 ...
- display:inline-block引发的间隙问题解决办法
在网页布局中我们经常会用到display:inline-block;好处是:能够将块状元素按照内联元素的方式布局,同时能设置宽高.个人感觉很好用,可是用多了慢慢的问题就来了? 1.display:in ...
- Sqli-labs less 50
Less-50 从本关开始我们开始进行order by stacked injection! 执行sql语句我们这里使用的是mysqli_multi_query()函数,而之前我们使用的是mysqli ...
- 无网络centos7中部署kubernetes
本文提供的kubernetes1.1实际为kubernetes0.8,最新kubernetes部署方式见下一篇文章:centos下kubernetes+flannel部署. 一.部署环境信息: 1)m ...
- linux权威指南 简记
/proc 目录,linxu系统以文件形式存放进程信息,这是一个虚拟的文件系统,不占有任何磁盘空间,当读取该文件系统时,系统内核会拦截动作,并动态产生文件与目录的内容 查看该文件夹,会发现很多已数字命 ...
- 链表(c语言实现)--------------小练习
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_SIZE 100 #d ...
- LCS最长公共子序列(最优线性时间O(n))
这篇日志主要为了记录这几天的学习成果. 最长公共子序列根据要不要求子序列连续分两种情况. 只考虑两个串的情况,假设两个串长度均为n. 一,子序列不要求连续. (1)动态规划(O(n*n)) (转自:h ...