I need to grab the href value from HTML like the following in C#:
<td class="tl"><a href="http://facebook.com/"target="_blank"><img src="images/poput_icon.png"/></a>
Can anyone show me how to do this? Are RegEx’s the best approach? I need to gather these from a page that contains 100s of links, but they all look like the above code. I want to ignore other href’s on the page.
Thanks in advance.
Jimmy
First, don’t use Regular Expressions to parse XML. See here for more detailed information on the whys and wherefores.
Second, you can use LINQ-to-XML to achieve this. Assuming you have loaded your XML snippet into an
XDocumentinstance (and therefore,tdis the root element), you can then do the following: