私はこのようなコードの行をいくつか持っています。XDocumentから重複したエントリを削除します。
XDocument rssDocDistinct = new XDocument(new XElement("rss",
new XElement("channel",
from node in rssDoc.Element("rss").Element("channel").Descendants("item")
select node)));
rssDocの個別の「アイテム」のみを取得する方法を教えてもらえますか?私は重複したくない。
ありがとうございました。
編集:rssDocDistinctはなし、重複項目の要素を次のようになります
<rss version="2.0">
<channel>
<title></title>
<link></link>
<description></description>
<copyright></copyright>
<ttl></ttl>
<item>
<title></title>
<description></description>
<link></link>
<pubDate></pubDate>
</item>
<item>
<title></title>
<description> </description>
<link></link>
<pubDate></pubDate>
</item>
</channel>
</rss>
(同じタイトルを持つアイテム、リンク、説明、pubDateのは一度だけ表示されます)
<item>
<title></title>
<description></description>
<link></link>
<pubDate></pubDate>
</item>
<item>
<title></title>
<description> </description>
<link></link>
<pubDate></pubDate>
</item>
編集: 助けていただきありがとうございます。私は、polishchucが提案するようにIEqualityComparerを作成する方法を考え出しました。
public class ItemComparer : IEqualityComparer<XElement>
{
#region IEqualityComparer<XElement> Members
public bool Equals(XElement x, XElement y)
{
return (string)x.Element("title") == (string)y.Element("title")
&& (string)x.Element("description") == (string)y.Element("description")
&& (string)x.Element("link") == (string)y.Element("link")
&& (string)x.Element("pubDate") == (string)y.Element("pubDate");
}
public int GetHashCode(XElement obj)
{
return ((string)obj.Element("title")).GetHashCode()
+ ((string)obj.Element("description")).GetHashCode()
+ ((string)obj.Element("link")).GetHashCode()
+ ((string)obj.Element("pubDate")).GetHashCode();
}
#endregion
}
これは私がちょうどすべてたい – BrokenGlass
それは「他の項目とは異なる少なくとも1つの属性値」を意味と仮定して、サンプルXMLを参照してくださいする必要があり、どのような「明確な」手段のあなたの指標に依存重複が削除されました。 – theDawckta
あなたのxmlを投稿せずに、誰もあなたに特定の答えを与えることはできません。 – BrokenGlass