Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it just me? I find LINQ to XML to be sort of cumbersome, compared to XPath
    text
    copied!<p>I am a C# programmer, so I don't get to take advantage of the cool XML syntax in VB.</p> <pre><code>Dim itemList1 = From item In rss.&lt;rss&gt;.&lt;channel&gt;.&lt;item&gt; _ Where item.&lt;description&gt;.Value.Contains("LINQ") Or _ item.&lt;title&gt;.Value.Contains("LINQ") </code></pre> <p>Using C#, I find <a href="http://en.wikipedia.org/wiki/XPath" rel="nofollow noreferrer">XPath</a> to be easier to think about, easier to code, easier to understand, than performing a multi-nested select using <a href="http://en.wikipedia.org/wiki/Language_Integrated_Query#LINQ_to_XML" rel="nofollow noreferrer">LINQ to XML</a>. Look at this syntax, it looks like Greek swearing: </p> <pre><code>var waypoints = from waypoint in gpxDoc.Descendants(gpx + "wpt") select new { Latitude = waypoint.Attribute("lat").Value, Longitude = waypoint.Attribute("lon").Value, Elevation = waypoint.Element(gpx + "ele") != null ? waypoint.Element(gpx + "ele").Value : null, Name = waypoint.Element(gpx + "name") != null ? waypoint.Element(gpx + "name").Value : null, Dt = waypoint.Element(gpx + "cmt") != null ? waypoint.Element(gpx + "cmt").Value : null }; </code></pre> <p>All the casting, the heavy syntax, the possibility for NullPointerExceptions. None of this happens with XPath. </p> <p>I like LINQ in general, and I use it on object collections and databases, but my first go-round with querying XML led me right back to XPath. </p> <p>Is it just me? </p> <p>Am I missing something? </p> <hr> <p><strong>EDIT</strong>: someone voted to close this as "not a real question". But it <em>is</em> a real question, stated clearly. The question is: <em>Am I misunderstanding something with LINQ to XML?</em></p>
 

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