【问题标题】:Lowercase in xml element names when using MvcContrib's XmlResult使用 MvcContrib 的 XmlResult 时 xml 元素名称中的小写
【发布时间】:2011-08-10 09:56:00
【问题描述】:

我有这样的课程

public class Reply
{
    public string Result { get; set; }
    public int Code { get; set; }
    public string Description { get; set; }
}

当我将它用作 XmlResult 构造函数的参数时,我得到一个输出,其中 xml 元素名称的第一个字母是大写的。但我需要它们是简单的小写字母。也许有某种我想念的属性?不幸的是,我没有找到关于 XmlResult 的任何文档。

【问题讨论】:

标签: c# asp.net-mvc xml mvccontrib


【解决方案1】:

为了进行序列化,您可以添加:

[XmlElement("loweredname")] 

[XmlAttribute("loweredname")]

分别用于 XML 元素和属性。希望这可以满足您的需求。

更新:你的类应该是这样的:

[XmlRoot("reply")]
public class Reply
{
    [XmlElement("result")]
    public string Result { get; set; }
    [XmlElement("code")]
    public int Code { get; set; }
    [XmlElement("description")]
    public string Description { get; set; }
}

【讨论】:

  • 是的,这正是我认为应该的。但是,我仍然无法将 XmlElement 应用于整个班级,所以我得到的是 而不是 。我是否需要创建一些将Reply 作为其属性的包装器,并在那里设置XmlElement?
  • 对类使用 [XmlRoot("loweredname")]
  • @HiveHicks 或 XmlType("loweredname") 如果它实际上不是根目录
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-05
相关资源
最近更新 更多