RuleSetAddTagProcessingCondition Method
Adds a rule which represents the condition when ProcessElementDelegate delegate should be executed.

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

Parameters

tagName
Type: SystemString
The name of the tag or for which to execute the delegate. Case-insensitive.
tagAttrs
Type: MailBee.HtmlTagAttributeCollection
The list of attributes any of which must exist in the definition of tagName tags in order to execute the delegate, or a null reference (Nothing in Visual Basic) to execute the delegate for any tags with tagName name (regardless of which attributes they have).
Exceptions
ExceptionCondition
MailBeeInvalidArgumentExceptiontagName is a null reference (Nothing in Visual Basic) or an empty string.
Remarks

For instance, if tagName is A and tagAttrs is a null reference, Process(RuleSet, ProcessElementDelegate) method will execute ProcessElementDelegate delegate (specified in del parameter) for all <A> tags in the document.

If tagName is INPUT and tagAttrs contains TYPE=IMAGE and TYPE=FILE attributes, Process(RuleSet, ProcessElementDelegate) method will execute the delegate for all <INPUT TYPE=IMAGE> and <INPUT TYPE=FILE> tags but not for <INPUT TYPE=TEXT> tags.

This method creates a Rule of ProcessingCondition type. Rules of other types have the same conditions (tag name and optional list of attributes). The only difference between rule types is what action to perform when the condition gets satisfied. ProcessingCondition rule simply calls the delegate. Other rules call the delegate first, then check the return value of the delegate and perform the specified action only if the delegate returned true.

Note Note
If Process(RuleSet, ProcessElementDelegate) method was called with del parameter set to a null reference, ProcessingCondition rule will have no effect. Rules of other types will be executed as if the delegate always returned true.

The above applies to both Process(RuleSet, ProcessElementDelegate) and ProcessToString(RuleSet, ProcessElementDelegate) methods.

Examples
This sample demonstrates removing of images from an HTML source and replacing of BR tags with HR tags.
// To use the code below, import these namespaces at the top of your code.
using System.IO;
using System.Net;
using MailBee;
using MailBee.Html;

class Sample
{
    // The delegate is used for processing of the HTML source.
    // All IMG tags will be removed and all BR tags will be replaced with HR tags.
    static bool ProcessDelegate(Element elem, Rule rule)
    {
        switch (elem.TagName.ToLower())
        {
            case "img":
                elem.Remove();
                break;
            case "br":
                elem.TagName = "hr";
                return false;
        }
        return true;
    }

    static void Main(string[] args)
    {
        // Create a new stream and load the HTML document into it.
        WebRequest myWebRequest = WebRequest.Create("http://www.afterlogic.com"); 
        WebResponse myWebResponse = myWebRequest.GetResponse(); 
        Stream receivingStream = myWebResponse.GetResponseStream();

        Processor htmlProcessor = new Processor();

        // Load the stream into Processor instance.
        htmlProcessor.LoadFromStream(receivingStream, Global.DefaultEncoding);

        ProcessElementDelegate del = new ProcessElementDelegate(ProcessDelegate);

        RuleSet rules = new RuleSet();

        // Add HTML processing rules.
        rules.AddTagProcessingCondition("img", null);
        rules.AddTagProcessingCondition("br", null);

        // Process the delegate and the rules.
        htmlProcessor.Dom.Process(rules, del);

        // Save the resulting HTML to disk.
        FileStream outStream = new FileStream(@"C:\Temp\afterlogic.html", FileMode.Create, FileAccess.Write, FileShare.None);

        htmlProcessor.SaveToStream(outStream, Global.DefaultEncoding);
        outStream.Close();
    }
}
See Also