So, I can easily use LINQ to XML to traverse a properly set-up XML document. But I'm having some issues figuring out how to apply it to an HTML table. Here is the setup:
Solution 1:
XElement myTable = xdoc.Descendants ("table" ).FirstOrDefault (xelem => xelem.Attribute ("class" ).Value == "inner" );
IEnumerable<IEnumerable<XElement>> myRows = myTable.Elements ().Select (xelem => xelem.Elements ());
foreach (IEnumerable<XElement> tableRow in myRows )
{
foreach (XElement rowCell in tableRow )
{
}
}
Copy Solution 2:
Once you have an XElement with the <table>
, you can loop through its child Elements()
.
Solution 3:
linq is like sql it performs set based operations.
You want to focus on using a foreach loop to iterate over the selected set of xelements -
Post a Comment for "Using Linq To Xml To Traverse An Html Table"