score:3
You look for "td"
elements but at the top level of the node you only find a "tr"
element. That's why you don't get any elements. Try this:
from c in info.Elements("tr").Elements("td")
Also, you should check if there are any elements in the sequence before calling First()
(or use FirstOrDefault()
which returns null if there is no element).
If you don't know the path and only want all "td"
elements with that tag value, you can also use the Descendants
extension method:
from c in info.Descendants("td")
score:0
Elements
would give you the immediate child elements of the root in this case info. You need to drill down to the elements you are looking for and then extract them by the Where
clause. In your case the immediate children are the <tr>
s.
Source: stackoverflow.com
Related Articles
- Linq to XML selecting a node bases on a attribute value
- Linq to Xml: selecting elements if an attribute value equals a node value in an IEnumerable<XElement>
- LINQ Source Code Available
- creating Linq to sqlite dbml from DbLinq source code
- How Update a node attribute in xml using Linq query?
- get Node by it's attribute in linq to xml
- source code for LINQ 101 samples
- LINQ to XML Select Nodes based on child node and attribute
- C#: LINQ to XML Show particular Node attribute values from XML file
- LINQ request for getting the furthest xml child node with an attribute
- get attribute value from xsd node using LINQ
- Get attribute value of parent node by Linq to XML
- Check XML node have attribute name with specific value - Parse XML using Linq
- Getting all attribute values from node by specifying the ancestor node using LINQ
- c# Linq or code to extract groups from a single list of source data
- How to load xml code block into existing xml file at a specific node using linq
- sub sub child node attributes according to some attribute value of child node of xml using linq
- Adding an attribute to xml document child node using linq
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities" - stumped!
- The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities
- How are people unit testing code that uses Linq to SQL
- Check if XML-node has attribute with Linq C#?
- The LINQ expression node type 'Invoke' is not supported in LINQ to Entities in entity framework
- Linq select object from list depending on objects attribute
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Find an XElement with a certain attribute name and value with LINQ
- Syntax to execute code block inside Linq query?
- Linq - Get items from the list based on "weight" and "order"
- linq to xml CDATA problem
- C# Linq - Given two lists, how do I tell if either of them are contained in each other
- Where do I put the "orderby group.key" in this LINQ statement?
- Model Design As Database Table Or Multi-Dimensional List?
- How to map properties to a columns
- Entity Framework GroupBy to Sql Generation
- Linq: How to make this work
- SQL query to LINQ expression
- How To Project a Line Number Into Linq Query Results
- LINQ: Can't filtering List<Model> data by .Contains
- linq nested query
- How to get IGrouping index with Linq to entities ? (NotSupportedException)
- Converting enum values into an string array
- Linq way to check if any other element matches expression while skipping itself
- Count XElements Grouped by Parent using LINQ
- groupby doesn't work in linq ,result are same like input
- Invocation order by a specific attribute
- Get the length of a Dictionary in VB.NET
- How can I sort on multiple fields with LINQ?