RuleSetAddTagReplacementRule Method (String, TagAttributeCollection, Element)
Adds a rule for replacing certain tags with the specified replacement element.

Namespace: MailBee.Html
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
public void AddTagReplacementRule(
	string tagName,
	TagAttributeCollection tagAttrs,
	Element replacement
)

Parameters

tagName
Type: SystemString
The name of the tag to be replaced. Case-insensitive.
tagAttrs
Type: MailBee.HtmlTagAttributeCollection
The list of attributes any of which must exist in the definition of tagName tags in order to trigger the rule's action, or a null reference (Nothing in Visual Basic) to apply the rule for any tags with tagName name (regardless of which attributes they have).
replacement
Type: MailBee.HtmlElement
The element which will replace the original element.
Exceptions
ExceptionCondition
MailBeeInvalidArgumentExceptiontagName is a null reference (Nothing in Visual Basic) or an empty string, or replacement is a null reference.
Remarks

The condition when this rule satisfies is the same as for ProcessingCondition rule (created with AddTagProcessingCondition(String, TagAttributeCollection) method). See AddTagProcessingCondition(String, TagAttributeCollection) 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.

Examples
This sample replaces all of tables with HTML comments in the HTML source.
// 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:\Temp\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));
    }
}
See Also