Adds a rule for changing attributes of HTML tags.
The condition when this rule satisfies is the same as for ProcessingCondition rule (created with AddTagProcessingCondition method). See AddTagProcessingCondition topic for the details which apply to the HTML processing rules of all types.
Once the matching tag was found and the delegate (if any) returned true, the processing continues as follows (depending on replaceMode value):
Note tagAttrs collection is not related with attrsToAdd or attrsToRemove in any way. tagAttrs only specifies attributes any of which the tagName tag must have in order to satisfy the rule condition. However, tagAttrs is not used later when the rule action begins.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidArgumentException | tagName is a null reference (Nothing in Visual Basic) or an empty string, or replaceMode is true and attrsToAdd does not match attrsToRemove. |
This sample change the background color of the HTML page to black.
[C#] // To use the code below, import these namespaces at the top of your code. using System; using System.IO; using System.Net; using MailBee; using MailBee.Html; class Sample { static void Main(string[] args) { // Create new stream with an HTML markup. WebRequest myWebRequest = WebRequest.Create("http://www.afterlogic.com"); WebResponse myWebResponse = myWebRequest.GetResponse(); Stream receivingStream = myWebResponse.GetResponseStream(); Processor htmlProcessor = new Processor(); htmlProcessor.LoadFromStream(receivingStream, Global.DefaultEncoding); RuleSet rules = new RuleSet(); // Create new rule for processing. TagAttributeCollection attributes = new TagAttributeCollection(); TagAttribute attribute = new TagAttribute(); attribute.Definition = "bgcolor = 'black'"; attributes.Add(attribute); rules.AddTagRemovalRule("link", null); rules.AddTagProcessingRule("body", null, attributes, null, false); // Processing of the rule. Console.WriteLine(htmlProcessor.Dom.ProcessToString(rules, null)); } }
[Visual Basic] ' To use the code below, import these namespaces at the top of your code. Imports System Imports System.IO Imports System.Net Imports MailBee Imports MailBee.Html Module Sample Sub Main() ' Create new stream with an HTML markup. Dim myWebRequest As WebRequest = WebRequest.Create("http://www.afterlogic.com") Dim myWebResponse As WebResponse = myWebRequest.GetResponse() Dim receivingStream As Stream = myWebResponse.GetResponseStream() Dim htmlProcessor As New Processor htmlProcessor.LoadFromStream(receivingStream, Global.DefaultEncoding) Dim rules As New RuleSet ' Create new rule for processing. Dim attributes As TagAttributeCollection = New TagAttributeCollection Dim attribute As TagAttribute = New TagAttribute attribute.Definition = "bgcolor = 'black'" attributes.Add(attribute) rules.AddTagRemovalRule("link", Nothing) rules.AddTagProcessingRule("body", Nothing, attributes, Nothing, False) ' Processing of the rule. Console.WriteLine(htmlProcessor.Dom.ProcessToString(rules, Nothing)) End Sub End Module
RuleSet Class | MailBee.Html Namespace