急急急C#XML序列化
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了急急急C#XML序列化相关的知识,希望对你有一定的参考价值。
如何序列化该类
public class BackUpEditionModel //Dll备份类
private string backUpEdition;
private DateTime backUpDate;
private DllInfo[] backUpDllInfoList;
private string description;
public BackUpEditionModel()
/// <summary>
/// 备份版本信息
/// </summary>
[XmlElement()]
public string BackUpEdition
get return this.backUpEdition;
set this.backUpEdition = value;
/// <summary>
/// 备份日期
/// </summary>
[XmlElement()]
public DateTime BackUpdate
get return this.backUpDate;
set this.backUpDate = value;
/// <summary>
/// 备份Dll的详细信息列表
/// </summary>
[XmlArrayItem(typeof(DllInfo))]
public DllInfo[] BackUpDllInfoList
get return this.backUpDllInfoList;
set this.backUpDllInfoList = value;
/// <summary>
/// 备份描述
/// </summary>
[XmlElement()]
public string Description
get return this.description;
set this.description = value;
该类的BackUpDllInfoList属性是这个类:
[XmlInclude(typeof(DllInfo))]
[Serializable]
public class DllInfo
private string dllName;
private string dllEdition;
private string dllDiscription;
public DllInfo()
/// <summary>
/// Dll名称
/// </summary>
[XmlElement()]
public string DllName
get return this.dllName;
set this.dllName = value;
/// <summary>
/// Dll版本信息
/// </summary>
[XmlElement()]
public string DllEdition
get return this.dllEdition;
set this.dllEdition = value;
/// <summary>
/// Dll描述
/// </summary>
[XmlElement()]
public string DllDiscription
get return this.dllDiscription;
set this.dllDiscription = value;
请问如何序列化第一个类到文本文档呢?
我总是报错生成XML文档出错"不应是类型 UpdateConfig.BackUpDllIO。使用 XmlInclude 或 SoapInclude 属性静态指定非已知的类型。"
各位大侠帮帮忙啊
但是如果你是想把这两个类序列化到XML文件,我这里有代码
首先在命名空间里面创建一个struct
public struct XmlElement
public BackUpEditionModel backUpEditionModel;
public DllInfo dllInfo;
public class Xml
private XmlElement xmlElement;
public XmlElement XmlElementAttribute
getreturn this.xmlElement;
setthis.xmlElement = value;
public bool SaveToXml(string path)
XmlSerializer xml = new XmlSerializer(typeof(XmlElement));
StreamWriter sw = new StreamWriter(path, false, Encoding.Default);
try
xml.Serialize(sw, xmlElement);
catch (Exception ex)
return false;
finally
sw.Close();
return true;
public bool loadFromXml(string path)
XmlSerializer xml = new XmlSerializer(typeof(XmlElement));
StreamReader sr = new StreamReader(path, Encoding.Default);
try
this.xmlElement = (XmlElement)xml.Deserialize(sr);
catch (Exception ex)
return false;
finally
sr.Close();
return true;
之后你再建立一个main方法,把你的路径进去就可以了 参考技术B 没见过这么复杂的XML序列化
要序列化哪个类只要加上Serializable属性
使用System.Xml.Serialization.XmlSerializer().Serialize(stream,new object())
就可以了 参考技术C 看MSDN这个帖
http://msdn.microsoft.com/zh-cn/library/system.xml.serialization.xmlserializer(VS.80).aspx
求大神解决,急急急!!!
在Win8系统上,连接Oracle数据库时候,出现这个错误
未能加载文件或程序集“Oracle.Web, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342”或它的某一个依赖项
请问是怎么回事?
以上是关于急急急C#XML序列化的主要内容,如果未能解决你的问题,请参考以下文章
Oracle 如何知道那个表用到哪个序列?急急急急急急急急急.....