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,CDataorProcessingInstruction; - its
Name, its source textRaw, itsStartandEndoffsets,IsSelfClosingandCommentData; - for a start tag,
Attributes, whichforeachlists with theirName,Value(still entity-encoded) andQuote.
The bodies of script, style, textarea and title are read as text.