日期:2014-05-18  浏览次数:21265 次

请教C# XML 序列化和反序列化时ElementName 相同 反射类型 时出错
类说明如下:ElementName中有两个全是等于“总计”的,序列化时候提示 反射类型 时出错
请教大家有遇上同样问题的吗?
namespace Contecmed.XML
{
  /// <summary>
  /// 室性早搏段
  /// </summary>
  public class VEXml
  {
  //室性总数
  private string totalVE = null;
  [XmlElement(ElementName = "室性总数")]
  public string TotalVE
  {
  get { return totalVE; }
  set { totalVE = value; }
  }

  //室性成对数
  private string totalVEPair = null;
  [XmlElement(ElementName = "室性成对数")]
  public string TotalVEPair
  {
  get { return totalVEPair; }
  set { totalVEPair = value; }
  }

  //室性速
  private VERunXml veRun = null;
  [XmlElement(ElementName = "室性速")]
  public VERunXml VERun
  {
  get { return veRun; }
  set { veRun = value; }
  }

  //室性千分比
  private string vePerMil = null;
  [XmlElement(ElementName = "室性千分比")]
  public string VEPerMil
  {
  get { return vePerMil; }
  set { vePerMil = value; }
  }

  //二联律总数
  private string totalVEBig = null;
  [XmlElement(ElementName = "二联律总数")]
  public string TotalVEBig
  {
  get { return totalVEBig; }
  set { totalVEBig = value; }
  }

  //总计
  private string sumVEBig = null;
  [XmlElement(ElementName = "总计")]
  public string SumVEBig
  {
  get { return sumVEBig; }
  set { sumVEBig = value; }
  }

  //三联律总数
  private string totalVETrig = null;
  [XmlElement(ElementName = "三联律总数")]
  public string TotalVETrig
  {
  get { return totalVETrig; }
  set { totalVETrig = value; }
  }

  //总计
  private string sumVETrig = null;
  [XmlElement(ElementName = "总计")]
  public string SumVETrig
  {
  get { return sumVETrig; }
  set { sumVETrig = value; }
  }

  //一分最大室性数
  private string maxMinuteVECount = null;
  [XmlElement(ElementName = "一分最大室性数")]
  public string MaxMinuteVECount
  {
  get { return maxMinuteVECount; }
  set { maxMinuteVECount = value; }
  }
  }
}


------解决方案--------------------
xml 要有相应的namespace才行。


 <室上性早搏>
<SumVEBig1:总计>123</SumVEBig1:总计>
<SumVEBig2:总计>456</SumVEBig2:总计>
</室上性早搏>

从xml反序列化,人都分不出来哪个是哪个,机器咋区分。

------解决方案--------------------
XML code
    [XmlRoot(ElementName = "室上性早搏")]
    public class VEXml
    {
        private int iD;
        [XmlElement(ElementName = "ID")]
        public int ID
        {
            get { return iD; }
            set { iD = value; }
        }
        priva