首页 > 编程语言 >C# 序列化与反序列化XML文件

C# 序列化与反序列化XML文件

时间:2023-04-25 11:59:39浏览次数:36  
标签:XML C# List reader var new 序列化

 1 //整理输出数据
 2 List<RowData> lisOutputData = new List<RowData>();
 3 foreach (var item in dicAssist.Keys)
 4 {
 5     string key = item + dicAssist[item];
 6     foreach (var itm in dicRowNumber[key])
 7     {
 8         lisOutputData.Add(dicRowData[itm]);
 9     }
10 }
11 Console.WriteLine("Excel数据读取并整理完成!" + Environment.NewLine);
12 
13 
14 //序列化集合为xml文件
15 Console.WriteLine("序列化集合为XML文件......");
16 
17 var reader = new XmlSerializer(typeof(List<RowData>));
18 //写入文件
19 using (var fs = File.OpenWrite(localEcnDataXmlFilePath))
20 {
21     reader.Serialize(fs, lisOutputData);
22 }
1 //反序列化XML文件为集合
2 var reader = new XmlSerializer(typeof(List<RowData>));
3 basicEcnData = new List<RowData>();
4 using (var fs = File.OpenRead(localEcnDataXmlFilePath))
5 {
6     basicEcnData = reader.Deserialize(fs) as List<RowData>;
7 }

 

标签:XML,C#,List,reader,var,new,序列化
From: https://www.cnblogs.com/xuanyuanhw/p/17352171.html

相关文章

  • HTML+CSS学习--HTML表单标签
     关注我了解更多web技术知识,带你一路“狂飙”到底!上岸大厂不是梦!表单1:表单标签<form></form>属性:action='接口地址'method='get/post'name='表单名称'2:表单控件<input>属性:type='控件类型'name:属性标识表单域的名称;Value:属性定义表单域的默认值,其他属......
  • Cesium加载ArcGIS Server4490且orgin -400 400的切片服务
    Cesium在使用加载Cesium.ArcGisMapServerImageryProvider加载切片服务时,默认只支持wgs84的4326坐标系,不支持CGCS2000的4490坐标系。如果是ArcGIS发布的4490坐标系的切片服务,如果原点在orginX:-180.0Y:90.0的情况下,我们可以通过WebMapTileServiceImageryProvider按照WMTS的方式......
  • SpringContextUtils
    importorg.springframework.beans.BeansException;importorg.springframework.beans.factory.NoSuchBeanDefinitionException;importorg.springframework.context.ApplicationContext;importorg.springframework.context.ApplicationContextAware;importorg.springfr......
  • DDP运行报错(单卡无错):ERROR:torch.distributed.elastic.multiprocessing.api:failed (e
    使用DDP时出现错误,但是单卡跑无错误。错误记录如下:RuntimeError:Expectedtohavefinishedreductionintheprioriterationbeforestartinganewone.Thiserrorindicatesthatyourmodulehasparametersthatwerenotusedinproducingloss.Youcanenableunu......
  • 百度ueditor 实现ctrl+v粘贴图片并上传、word粘贴带图片
    ​ 自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了。一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器)中时,编辑器都无法自动上传图片。需要用户手动一张张上传Word图片。如果只有一张图片还能够接......
  • 【HMS Core】Health Kit取消授权接口怎么辨识是哪个用户取消授权呢?
    【问题描述1】取消授权接口怎么辨识是哪个用户取消授权呢? 【解决方案】取消授权时,请求头中需要传入access_token,此access_token对应某个用户。详情请查看取消授权接口:https://developer.huawei.com/consumer/cn/doc/development/HMSCore-References/cancel-scpoes-00000010......
  • spring IoC和DI
    IoC控制反转IoC是InversionofControl的缩写。他是一种软件设计原则,用于减少代码之间的耦合度。在IoC中,对象不在负责管理和创建他们依赖的对象,而是将这些任务交给外部容器,来完成。这样做可以使代码更加松散耦合,更容易扩展和维护。控制反转的主要思想是将对象的创建和管理交给Io......
  • SpringSecurity从入门到精通:认证配置详解&权限系统的作用
    认证配置详解Configpackagecom.sangeng.config;importcom.sangeng.filter.JwtAuthenticationTokenFilter;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.context.annotation.Bean;importorg.springframework.context.ann......
  • 在CentOS上安装和配置Spark Standalone
    1.确认Java已安装在CentOS上运行以下命令以确认Java是否已安装:java-version如果Java未安装,请按照以下步骤进行安装:sudoyuminstalljava-1.8.0-openjdk-develx 修改/etc/profile文件,末尾添加exportJAVA_HOME=/usr/local/src/jdk1.8.0_291exportJRE_HOME=${JAVA_......
  • Spring Boot Configuration Annotation Processor not configured
    一、Springboot自定义配置实现自动提示@ConfigurationProperties的作用:让JavaBean中属性值要和配置文件进行映射@Getter@Setter@ConfigurationProperties(prefix="jwt")publicclassJwtProperties{/***JWT加解密使用的密钥*/privateString......