Castor:嵌套元素



给定以下域对象:

public class Domain {
   private String field1 = "one";
   private String field2 = "two";
}
mapping.xml文件应该如何结构化,使XML输出看起来像这样:
<DomainObjects>
  <row field1="one">
      <field2>two</field2>
  </row>
<DomainObjects>

其中"DomainObjects"为静态标签。

Thanks very much

[XmlType("domain"), XmlRoot("domain")]
public class Domain {
    [XmlAttribute("field1")]
    public string field1 {get;set;}
    [XmlAttribute("field2")]
    public decimal field2 {get;set;}

也可以得到值

var result = from e in XDocument.Load("yourfile.xml").Descedants("Domain")
                  select new Domain{field1=e.Element("field1").Value,field2=e.Element("field2").Value};

相关内容

  • 没有找到相关文章