Castor: Nesting Elements

Given the following domain object:

public class Domain { private String field1 = "one"; private String field2 = "two"; } 

how the map.xml file should be structured, so the XML output looks like this:

 <DomainObjects> <row field1="one"> <field2>two</field2> </row> <DomainObjects> 

where " DomainObjects " is a static label.

Many thanks

+8
castor
source share
1 answer
 [XmlType("domain"), XmlRoot("domain")] public class Domain { [XmlAttribute("field1")] public string field1 {get;set;} [XmlAttribute("field2")] public decimal field2 {get;set;} 

You can also get values

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

All Articles