I have a small function that removes extra spaces, tabs, new lines, line breaks from a piece of html.
One of the pages that gets processed by this code, contains an HTML table, that I need to skip one of its rows from being minifed, <tr class="navtable">
The table structure is:
If someone could show me how to achieve this that would be awesome. I am new at coding, but I will try to follow up the best I can.
Thank you very much.
One of the pages that gets processed by this code, contains an HTML table, that I need to skip one of its rows from being minifed, <tr class="navtable">
The table structure is:
<table id="TopNav" class="resultsNav" cellspacing="0" cellpadding="0" border="0" style="border-collapse:collapse;">
<tr class="navtable1">
<td>
<div class="navPagesTop">
<div class="navSelFL navPriceRefinements">
<select autocomplete="off" class="navSelPerPage navSelPrice" id="refShopByPrice" onchange="waitRefine(this.id, this.value)" >
<option value="55_100">$55 to $100 (19)</option>
<option value="100_110">$100 to $110 (7)</option>
<option value="110_165">$110 to $165 (54)</option>
<option value="165_200">$165 to $200 (14)</option>
<option value="200_250">$200 to $250 (3)</option>
<option value="250_400">$250 to $400 (2)</option>
<option selected value="">Filter By Price</option>
</select>
</div>
<div class="navSelFL navOrRefinements"> or </div>
<div class="navSelFL navBrandRefinements">
<select autocomplete="off" class="navSelPerPage navSelBrand" id="refShopByBrand" onchange="waitRefine(this.id, this.value)" >
<option value="carhartt">Carhartt (21)</option>
<option value="caterpillar">Caterpillar (3)</option>
<option value="danner">Danner (5)</option>
<option value="dingo">Dingo (1)</option>
<option value="georgia-boot">Georgia Boot (10)</option>
<option value="hi-tec">Hi-Tec (2)</option>
<option value="irish-setter">Irish Setter (8)</option>
<option value="john-deere-branded-items">John Deere Branded Items (8)</option>
<option value="keen">Keen (5)</option>
<option value="lacrosse">LaCrosse (1)</option>
<option value="rocky">Rocky (7)</option>
<option value="thorogood-shoes">Thorogood Shoes (4)</option>
<option value="timberland-pro">Timberland Pro (9)</option>
<option value="wolverine">Wolverine (8)</option>
<option selected value="">Filter By Brand</option>
</select>
</div>
</div>
</td>
</tr>
<tr class="navtable">
<td class="navSelPerPage" align="center" colspan="5" style="white-space:nowrap;">
<div class="navPages">
<div class="navSelFL navArrowPrev">
<a class="navArrowsSelected" rel="prev" href="/plain-toe-leather?perPage=20#prdRslts"><< Previous</a>
</div>
<div class="navSelFL navPageNumbers">
<span class="navSelUnSelected"><a href="/plain-toe-leather?perPage=20#prdRslts" rel="prev"> 1 </a></span>
<span class="navSelSelected"> 2 </span>
<span class="navSelUnSelected"><a href="/plain-toe-leather/3?perPage=20#prdRslts" rel="next"> 3 </a></span>
<span class="navSelUnSelected"><a href="/plain-toe-leather/4?perPage=20#prdRslts"> 4 </a></span>
<span class="navSelUnSelected"><a href="/plain-toe-leather/5?perPage=20#prdRslts"> 5 </a></span>
</div>
<div class="navSelFL navArrowNext">
<a class="navArrowsSelected" rel="next" href="/plain-toe-leather/3?perPage=20#prdRslts">Next >></a>
</div>
<div class="navSelFL navPageList">
<span class="navSelBlack">Page 2 of 5</span>
</div>
</div>
</td>
</tr>
</table>
And the code that does the removal of extra whie space, tabs, line breaks. Public Shared Function MinifyStringContent(ByVal strContent As String) As String
Dim htmlDoc As New HtmlAgilityPack.HtmlDocument
Dim strNoSpaces As String = Regex.Replace(strContent, "\s{2,}", " ")
Dim oldFlags As New HtmlAgilityPack.HtmlElementFlag
htmlDoc.OptionDefaultStreamEncoding = Encoding.UTF8
If HtmlAgilityPack.HtmlNode.ElementsFlags.ContainsKey("option") Then
HtmlAgilityPack.HtmlNode.ElementsFlags("option") = HtmlAgilityPack.HtmlElementFlag.Closed
Else
HtmlAgilityPack.HtmlNode.ElementsFlags.Add("option", HtmlAgilityPack.HtmlElementFlag.Closed)
End If
htmlDoc.LoadHtml(strNoSpaces)
If Not IsNothing(strNoSpaces) AndAlso strNoSpaces <> "" Then
For Each textnode In htmlDoc.DocumentNode.SelectNodes("//text()")
If Not (textnode.ParentNode.Name = "script" OrElse textnode.ParentNode.Name = "style") Then
textnode.InnerHtml = textnode.InnerText.Replace(vbCrLf, "").Replace(" ", " ").Replace(vbTab, "").Replace(vbNewLine, "")
End If
Next
End If
Return htmlDoc.DocumentNode.OuterHtml
End Function
Is there a htmal agility pack method that I can use on my function to tell it to not process the "TopNav" table row with class "navtable"?If someone could show me how to achieve this that would be awesome. I am new at coding, but I will try to follow up the best I can.
Thank you very much.