Adds a rule for replacing certain tags with the specified replacement element.
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.
The action for this rule removes the matching tag with all its inner contents and puts the replacement tag at the same position in the document.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidArgumentException | tagName is a null reference (Nothing in Visual Basic) or an empty string, or replacement is a null reference. |
This sample replaces all of tables with HTML comments in the HTML source.
[C#] // To use the code below, import these namespaces at the top of your code. using System; using MailBee.Mime; using MailBee.Html; class Sample { static void Main(string[] args) { // Load HTML message from file. MailMessage message = new MailMessage(); message.LoadMessage(@"C:\message.eml"); Processor htmlProcessor = new Processor(); htmlProcessor.Dom.OuterHtml = message.BodyHtmlText; RuleSet rules = new RuleSet(); Element elem = new Element(); elem.TagName = "!--table was here--"; rules.AddTagReplacementRule("table", null, elem); htmlProcessor.Dom.Process(rules, null); // Process the rule and display the results. 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 MailBee.Mime Imports MailBee.Html Module Sample Sub Main() ' Load HTML message from file. Dim message As New MailMessage message.LoadMessage("C:\message.eml") Dim htmlProcessor As New Processor htmlProcessor.Dom.OuterHtml = message.BodyHtmlText Dim rules As New RuleSet Dim elem As New Element elem.TagName = "!--table was here--" rules.AddTagReplacementRule("table", Nothing, elem) htmlProcessor.Dom.Process(rules, Nothing) ' Process the rule and display the results. Console.WriteLine(htmlProcessor.Dom.ProcessToString(rules, Nothing)) End Sub End Module
RuleSet Class | MailBee.Html Namespace | RuleSet.AddTagReplacementRule Overload List