Relatude Help

Reading

using Relatude.CMS.Utils;

var images = 0;
var reader = new HtmlReader(html);
while (reader.Read()) {
    if (reader.Kind == HtmlTokenKind.StartTag && reader.Name.Equals("img", StringComparison.OrdinalIgnoreCase)) images++;
}

HtmlReader is a ref struct over a ReadOnlySpan<char>. Each call to Read() moves to the next token, which has:

  • a Kind: Text, StartTag, EndTag, Comment, Doctype, CData or ProcessingInstruction;
  • its Name, its source text Raw, its Start and End offsets, IsSelfClosing and CommentData;
  • for a start tag, Attributes, which foreach lists with their Name, Value (still entity-encoded) and Quote.

The bodies of script, style, textarea and title are read as text.