Code: (Using HTML Agility Pack)
Dim moHtmlParser As HtmlDocument = New HtmlDocument
moHtmlParser.LoadHtml(htmlString)
Dim maStyles As New List(Of String)
Dim moStyleNodes As HtmlNodeCollection = moHtmlParser.DocumentNode.SelectNodes("//link")
Html:
<head runat="server">
<script src="Scripts/JScript1.js" type="text/javascript" ></script>
<link href="Stylesheets/StyleSheet1.css" rel="Stylesheet" type="text/css" />
<link href="Stylesheets/StyleSheet2.css" rel="Stylesheet" type="text/css" />
<link href="Stylesheets/StyleSheet3.css" rel="Stylesheet" type="text/css" />
<title>Untitled Page</title>
No matches? moStyleMatches is always Nothing. The Html shown is from the Head, for what it’s worth. I’m able to match other tags in there(script, title) no problem.
Update:
Even after removing the ElementsFlag for "link" tags, it just wouldn’t pick up the tags.
I worked around it with this code:
Dim moStyleNodes As HtmlNodeCollection = moHtmlParser.DocumentNode.SelectNodes("//*[@rel]")
I then made sure that the "rel" was "stylesheet" before working with the node.
Works for now, but doesn’t explain why it wasn’t working in the first place.
Even after removing the ElementsFlag for “link” tags, it just wouldn’t pick up the tags.
I worked around it with this code:
I then made sure that the “rel” was “stylesheet” before working with the node.
Works for now, but doesn’t explain why it wasn’t working in the first place.