HtmlStreamWriter Class

  • Experimental (WEBPLATEXP0002)

The writer of the HTML streamed into an element or a shadow root (https://whatpr.org/html/12758/dynamic-markup-insertion.html#stream-html), returned by Element.StreamAppendHtmlUnsafe and the other streaming methods: the chunks are parsed as they are written, by a fragment parser that inserts the nodes directly into the target (before the reference child), so the template for elements patch the content as it arrives. In JavaScript, the methods return a WritableStream whose sink is this writer.

[Experimental("WEBPLATEXP0002", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public sealed class HtmlStreamWriter

Properties

NameDescription
IsCompletedGets whether the stream is closed or aborted: the writer cannot be written to anymore.

Gets whether the stream is closed or aborted: the writer cannot be written to anymore.

public bool IsCompleted { get; }

Property value

bool

Methods

NameDescription
Abort()Aborts the parser: the rest of the input is not parsed, and the script elements that are still open never run.
Close()Parses the end of the input (the close algorithm of https://whatpr.org/html/12758/dynamic-markup-insertion.html#stream-html).
Write(string)Parses a chunk of HTML, after the previous chunks (the write algorithm of https://whatpr.org/html/12758/dynamic-markup-insertion.html#stream-html).

Aborts the parser: the rest of the input is not parsed, and the script elements that are still open never run.

public void Abort()

Parses the end of the input (the close algorithm of https://whatpr.org/html/12758/dynamic-markup-insertion.html#stream-html).

public void Close()

Exceptions

InvalidOperationException
The writer is closed or aborted.

Write(string)

HtmlStreamWriter.cs

Parses a chunk of HTML, after the previous chunks (the write algorithm of https://whatpr.org/html/12758/dynamic-markup-insertion.html#stream-html).

public void Write(string chunk)

Parameters

chunk string

Exceptions

InvalidOperationException
The writer is closed or aborted.
DomException
The reference child is no longer a child of the target: the parser is aborted.