Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The operation you want here is a Zip to pair up corresponding elements in your two sequences of books. That operator is being <a href="http://community.bartdesmet.net/blogs/bart/archive/2008/11/03/c-4-0-feature-focus-part-3-intermezzo-linq-s-new-zip-operator.aspx" rel="nofollow noreferrer">added in .NET 4.0</a>, but we can fake it by using Select to grab the books' indices and joining on that:</p> <pre><code>var res = from b1 in xml1.Descendants("book") .Select((b, i) =&gt; new { b, i }) join b2 in xml2.Descendants("book") .Select((b, i) =&gt; new { b, i }) on b1.i equals b2.i </code></pre> <p>We'll then use a second join to compare the values of attributes by name. Note that this is an inner join; if you did want to include attributes missing from one or the other you would have to do quite a bit more work.</p> <pre><code> select new { Row = b1.i, Diff = from a1 in b1.b.Attributes() join a2 in b2.b.Attributes() on a1.Name equals a2.Name where a1.Value != a2.Value select new { Name = a1.Name, Value1 = a1.Value, Value2 = a2.Value } }; </code></pre> <p>The result will be a nested collection:</p> <pre><code>foreach (var b in res) { Console.WriteLine("Row {0}: ", b.Row); foreach (var d in b.Diff) Console.WriteLine(d); } </code></pre> <p>Or to get multiple rows per book:</p> <pre><code>var report = from r in res from d in r.Diff select new { r.Row, Diff = d }; foreach (var d in report) Console.WriteLine(d); </code></pre> <p>Which reports the following:</p> <pre><code>{ Row = 0, Diff = { Name = image, Value1 = C01, Value2 = C011 } } { Row = 1, Diff = { Name = name, Value1 = ASP.NET, Value2 = ASP.NET 2.0 } } { Row = 3, Diff = { Name = id, Value1 = 20507, Value2 = 20508 } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload