0
如何在LINQ查询中检查属性的值是否为空。如果它不是null,那么将该属性添加到XML元素中?根据输入将属性添加到XML元素
为前:一是= AAA,最后= BBB,后缀=小那么 我的XML应该像(因为我没有通过为前缀的任何值,并键入他们不应该出现在XML)
<Subject>
</Name First= "AAA" Last ="BBB" Suffix="Jr">
</Subject>
感谢 BB
from i in DriverNames
select new XElement(Subject,
new XElement(Name,
new XAttribute("type", i.nameType),
new XAttribute(First, i.First.ToString().Trim().ToUpper()),
new XAttribute(last, i.Last.ToString().Trim().ToUpper()),
new XAttribute(Prefix, i.Prefix.ToString().Trim().ToUpper()),
new XAttribute(Suffix, i.Suffix.ToString().Trim().ToUpper())
))
谢谢安东尼,这并没有解决我的问题。现在你的代码如下:foos.Add(new Foo(){Bar =“”});那么产生的XML是。但我不希望显示在我的结果XML中。 –
BumbleBee
2011-02-01 19:17:09