Union with LINQ to XML
Posted
by Ryan Riley
on Stack Overflow
See other posts from Stack Overflow
or by Ryan Riley
Published on 2009-02-02T19:59:41Z
Indexed on
2010/05/03
18:48 UTC
Read the original article
Hit count: 448
I need to union two sets of XElements into a single, unique set of elements. Using the .Union() extension method, I just get a "union all" instead of a union. Am I missing something?
var elements = xDocument.Descendants(w + "sdt")
.Union(otherDocument.Descendants(w + "sdt")
.Select(sdt =>
new XElement(
sdt.Element(w + "sdtPr")
.Element(w + "tag")
.Attribute(w + "val").Value,
GetTextFromContentControl(sdt).Trim())
)
);
© Stack Overflow or respective owner