问师傅反序列化和序列化到底是什么,

然后师傅鄙视一下我的智商,让我做个反序列化解析XML。

一边听着师傅在旁边跟女朋友打电话收到暴击伤害,一边写,搞了一个半小时。

XML文件:

 <?xml version="1.0" encoding="utf-8" ?>

 <PRODUCT>

 <SatelliteId>TERRA</SatelliteId>

 <SensorId>MODIS</SensorId>

 <ProductId>HAZ</ProductId>

 <!--Inversion Combine-->

 <ProductType>Inversion</ProductType>

 <!--输入参数为单或多个文件(文件以;间隔,NPP数据为文件夹)-->
<InputDataFile>/DPS/Data/xxx.hdf</InputDataFile> <InversionArgs> <!--参数列表--> <InversionArg name="" value=""/> </InversionArgs> <!--输出结果及日志文件目录--> <OutputDataFilePath>/DPS/Data/L2/PRD/</OutputDataFilePath> <OutputDataFileList> <OutputDataFile name="" value="Hxxx.hdf" /> <OutputDataFile name="" value="Hxx.hdf" /> <OutputDataFile name="" value="Hxxx.hdf"/> </OutputDataFileList> <LogInfoFile>xxxxx.log</LogInfoFile> </PRODUCT>

类与调用代码:

 using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization; namespace ConsoleApplication1
{
[Serializable()]
public class PRODUCT
{
public PRODUCT() { }
public string SatelliteId { get; set; }
public string SensorId { get; set; }
public string ProductId { get; set; }
public string ProductType { get; set; }
public string InputDataFile { get; set; } [XmlArray("InversionArgs")]
[XmlArrayItem("InversionArg", typeof(namevlue))]
public List<namevlue> InversionArgs { get; set; }
public string OutputDataFilePath { get; set; } [XmlArray("OutputDataFileList")]
[XmlArrayItem("OutputDataFile", typeof(namevlue))]
public List<namevlue> OutputDataFileList { get; set; }
public string LogInfoFile { get; set; }
} [Serializable()]
public class namevlue
{
[XmlAttribute]
public string name { get; set; }
[XmlAttribute]
public string value { get; set; }
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("+++++开始+++++");
try
{
using (StreamReader sr = new StreamReader(@"D:\My CShirp soft\ConsoleApplication1\ConsoleApplication1\ProductPara.xml"))
{
XmlSerializer xmldes = new XmlSerializer(typeof(PRODUCT));
var re = xmldes.Deserialize(sr);
Console.WriteLine(re);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
Console.WriteLine("+++++结束+++++");
Console.Read();
}
}
}

C# 序列化简单格式XML的更多相关文章

  1. XML系列之--对电文格式XML的简单操作(三)

    前两章介绍了关于Linq创建.解析SOAP格式的XML,在实际运用中,可能会对xml进行一些其它的操作,比如基础的增删该查,而操作对象首先需要获取对象,针对于DOM操作来说,Linq确实方便了不少,如 ...

  2. C实现简单的xml格式文件

    今天在工作中遇到了一个需要处理xml格式的字符串,需求是修改某个固定的value值,并且还要把这个xml的key和value按照原本的格式在推送回去. 如果使用库,就显得太臃肿了,就想写个简单的dem ...

  3. 一个简单的XML与数组之间的转换

    xml是网络使用最多的数据交换格式,所以,不掌握怎么操作它,又有蛋疼的了. php中可以操作xml的类/函数很多,个人认为最简单的是SimpleXMLElement这个类,它的使用就跟其名字一样:简单 ...

  4. .net下二进制序列化的格式分析[转]

    .net下二进制序列化的格式分析[转] -- 综合应用 (http://www.Host01.Com/article/Net/00020003/) --- .net下二进制序列化的格式分析 (http ...

  5. 001-RESTful服务最佳实践-RestFul准则、HTTP动词表示含义、合理的资源命名、响应格式XML和JSON

    一.概述 因为REST是一种架构风格而不是严格的标准,所以它可以灵活地实现.由于这种灵活性和结构自由度,对设计最佳实践也有很大的差异. API的方向是从应用程序开发人员的角度考虑设计选择. 幂等性 不 ...

  6. [.net 面向对象程序设计进阶] (11) 序列化(Serialization)(三) 通过接口 IXmlSerializable 实现XML序列化 及 通用XML类

    [.net 面向对象程序设计进阶] (11) 序列化(Serialization)(三) 通过接口 IXmlSerializable 实现XML序列化 及 通用XML类 本节导读:本节主要介绍通过序列 ...

  7. 序列化对象为xml字符串

    /// <summary>    /// 序列化对象为xml字符串    /// </summary>    /// <param name="obj" ...

  8. 使用XML序列化器生成XML文件和利用pull解析XML文件

    首先,指定XML格式,我指定的XML格式如下: <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <message&g ...

  9. spring mvc3中JACKSON序列化日期格式的问题 - 墙头草的Java - BlogJava

    body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...

随机推荐

  1. 【译】第七篇 SQL Server代理作业活动监视器

    本篇文章是SQL Server代理系列的第七篇,详细内容请参考原文 在这一系列的上一篇,你创建并配置SQL Server代理作业.每个作业有一个或多个步骤,可能包含大量的工作流.在这篇文章中,将查看作 ...

  2. jquery ajax complete 方法

    jquery ajax var ajaxTimeoutTest = $.ajax({ url:'',  //请求的URL timeout : 1000, //超时时间设置,单位毫秒 type : 'g ...

  3. Oracle03--子查询

    1. 子查询 子查询也称之为嵌套子句查询. 1.1. 语法 语法上的运行使用规则: l 子查询 (内查询.嵌套子句) 在主查询之前一次执行完成.(子查询先执行) l 子查询的结果被主查询使用 (外查询 ...

  4. mysql中使用日期加减时无法识别年-月格式数据的问题,%Y-%m"这种格式数据

    最新做报表统计的时候处理按月统计部分时发现,虽然使用 DATE_FORMAT( time, '%Y-%m' ) 函数可以将日期格式转成年-月,但是如果是参数是年-月格式,即"2018-10& ...

  5. DevExpress 行事历(Scheduler)的常用属性、事件和方法

    一.TcxScheduler[TcxScheduler常用属性]1.Storage    - 邦定一个Storage为Scheduler显示提供数据 2.DateNavigate.ColCount   ...

  6. csv导入mysql提示错误[Error Code] 1290 - The MySQL server is running with the --secure-file-priv option 解决方法【转】

    解决方法: 1.进入mysql查看secure_file_prive的值 mysql>SHOW VARIABLES LIKE "secure_file_priv"; secu ...

  7. 简单计算器的C实现-函数指针,main函数传参

    /** 程序功能:简单计算器,实现加减乘除平方* 作者版本日期:2015.11.08 zhouhb OK* 源代码:李明 <新概念C语言培训>第33集 C语言Shell命令解释器的实现* ...

  8. 洛谷P2886牛继电器

    传送门啦 倍增 $ Floyd $ 注意结构体里二维数组不能开到 $ 2000 $ #include <iostream> #include <cstdio> #include ...

  9. python之路:python基础3

    ---恢复内容开始--- 本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8.内置函数 温故知新 1. 集合 ...

  10. python类型学习

    python类型学习 标准类型 数字 Integer 整型 Boolean 布尔型 Long integer 长整型 Floating point real numer  浮点型 Complex nu ...