c# 序列化XML文件时,子类的名称命名
2021-04-13 05:26
标签:odi weight 文件 sch color except xml文件 class nbsp 关键点: 序列化的代码如下: c# 序列化XML文件时,子类的名称命名 标签:odi weight 文件 sch color except xml文件 class nbsp 原文地址:https://www.cnblogs.com/wjx-blog/p/8985684.html [XmlRoot(ElementName = "product")]
public class WMS_Query_ProductInfo
{
public string skuCode { get; set; }
public float normalQuantity { get; set; }
public float defectiveQuantity { get; set; }
public float averageWeight { get; set; }
public int? lineNo { get; set; }
[XmlArray("batchs"), XmlArrayItem("batch")]
public List
public class WMS_Query_Batch
{
public string fixStatusCode { get; set; }
public DateTime? productionDate { get; set; }
public DateTime? expiryDate { get; set; }
public string packCode { get; set; }
public string uomCode { get; set; }
public decimal? quantity { get; set; }
}
上面两个类序列化后的文件如下:
xml version="1.0" encoding="utf-8" standalone="yes"?>
product>
skuCode>dddskuCode>
normalQuantity>0normalQuantity>
defectiveQuantity>0defectiveQuantity>
averageWeight>0averageWeight>
lineNo p2:nil="true"
xmlns:p2="http://www.w3.org/2001/XMLSchema-instance" />
batchs>
batch>
productionDate p4:nil="true"
xmlns:p4="http://www.w3.org/2001/XMLSchema-instance" />
expiryDate>2018-05-03T15:38:03.2177502+08:00expiryDate>
packCode>ddfpackCode>
uomCode>dduomCode>
quantity>1212quantity>
batch>
batchs>
product>
[XmlArray("batchs"), XmlArrayItem("batch")]
public ListWMS_Query_Batch> batchs { get; set; }
WMS_Query_ProductInfo product = new WMS_Query_ProductInfo();
product.skuCode = "ddd";
product.batchs = new List
public static object Deserialize(Type type, string xml)
{
try
{
using (StringReader sr = new StringReader(xml))
{
XmlSerializer xmldes = new XmlSerializer(type);
return xmldes.Deserialize(sr);
}
}
catch (Exception e)
{
Log.Log4net.Error(e.Message);
return null;
}
}
上一篇:C#关键字—方法参数
下一篇:C#常量
文章标题:c# 序列化XML文件时,子类的名称命名
文章链接:http://soscw.com/index.php/essay/75048.html