0
我正在尝试使用来自类的数据来生成XML文件,该类具有与名称关联的名称和多个地址。我迷路了@向XElement添加了多个地址。 有人可以帮我。 在此先感谢 BB。使用LINQ将对象构建为对象
我的课表:
public class Subject
{
public ClueName name { get; set; }
public List driverAddress { get; set;}
}
public class DriverAddress
{
public string house { get; set; }
public string street1 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string zip4 { get; set; }
}
private string BuildRequestXML(List <Subject> input)
{
string subjectId = "S1" ;
XElement req = new XElement("order",
new XElement("order_dataset",
new XElement("subjects",
from i in input
select
new XElement("subject", new XAttribute("id", subjectId),
new XElement("name",
new XElement("first",i.name.first),
new XElement("middle", i.name.middle),
new XElement("last", i.name.last)
)
)
),
new XElement("addresses",
input.Select(c => {c.driverAddress.Select (d =>
new XElement("address",
new XElement("street1",d.street1),
new XElement("city",d.city),
new XElement("state",d.state),
new XElement("postalcode",d.postalcode)
)).ToList();
}).ToList()
)
)
);
}
谢谢。我的要求是所有主题都应该在标签下,并且所有地址都在标签下。所以,“input.Select(c => {c.driverAddress.Select(d =>”完全不依赖于“我” –
BumbleBee
2010-12-09 23:21:34