xmlSerializer怎么在C#项目中使用
作者
xmlSerializer怎么在C#项目中使用?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
publicclassEntity
{
publicEntity()
{
}
publicEntity(stringc,stringf)
{
name=c;
school=f;
}
publicstringname;
publicstringschool;
}使用时声明
List<Entity>entityList=null; XmlSerializerxs=newXmlSerializer(typeof(List<Entity>));
读入
using(StreamReadersr=newStreamReader(configPath))
{
entityList=xs.Deserialize(sr)asList<Entity>;
}输出
using(StreamWritersw=File.CreateText(configPath))
{
xs.Serialize(sw,entityList);
}对应的xml
<?xmlversion="1.0"encoding="utf-8"?> <ArrayOfEntityxmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Entity> <Name>Alice</Name> <School>SJTU</School> </Entity> <Entity> <Name>Cici</Name> <School>CSU</School> </Entity> <Entity> <Name>Zero</Name> <School>HIT</School> </Entity> </ArrayOfEntity>
关于 xmlSerializer怎么在C#项目中使用问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注恰卡编程网行业资讯频道了解更多相关知识。
目录
推荐阅读
-
JAVA实现HTML转PDF的五种方法详解
-
MySQL创建和删除索引命令CREATE/DROP INDEX使用方法详解
-
深入理解 JavaScript 原型和构造函数创建对象的机制
-
ZooKeeper和Eureka有什么区别?注册中心如何选择?
-
ZooKeeper是什么?分布式系统开发者必读入门指南
-
JavaScript防抖与节流函数怎么写?高频事件优化技巧详解
-
c++中sprintf函数使用方法及示例代码详解
在C++编程中,格式化输出是常见的需求。虽然cout提供了基本的输出功能,但在需要精确控制输出格式(如指定宽度、精度、进制等)...
-
Swagger 接口注解详解教程:@Api、@ApiOperation、@ApiModelProperty 全解析
-
Python变量命名规则全解析:打造规范、可读性强的代码风格
-
OpenSSL是什么?OpenSSL使用方法详解
