2012-05-14 3 views
0

loc 요소를 기반으로하는 내 Google 사이트 맵에서 중복을 찾고 싶습니다.Google 사이트 맵에서 중복 찾기

샘플 XML :

<?xml version="1.0" encoding="UTF-8"?> 
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xsi:s chemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <url><loc>http://mysite.net/Members.aspx</loc><lastmod>2011-07-01</lastmod></url>  
    <url><loc>http://mysite.net/Topics.aspx</loc><lastmod>2011-05-27</lastmod></url> 
    <url><loc>http://mysite.net/Members.aspx</loc><lastmod>2011-07-02</lastmod></url>  
</urlset> 

샘플 LINQ :

  var duplicates = (from req in doc.Descendants("urlset") 
          group req by req.Descendants("//loc").First().Value 
           into g 
           where g.Count() > 1 
          select g.Skip(1)).SelectMany(elements => elements 
         ); 

어떻게 중복 와서는 빈 반환?

답변

0

귀하의 질의 요소를 찾을 수 없습니다. 필요 이상으로 복잡합니다.

XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; 
var duplicates = 
    from loc in doc.Root.Elements(ns + "url").Elements(ns + "loc") 
    group loc by loc.Value into g 
    where g.Count() > 1 
    select g.Key; 
0

doc.Descendants("urlset")은 하나의 요소 (<urlset>) 만 반환합니다.

당신은 <url> 요소를 선택해야합니다 네임 스페이스를 지정하지 않았기 때문에

from u in doc.Descendants("url") 
group u by u.Element("loc").Value into g 
from elem in g.Skip(1) //This is the SelectMany() 
select elem