XmlDocumentParser Class

Parses XML documents (https://html.spec.whatwg.org/multipage/xhtml.html#parsing-xhtml-documents). External entities are never loaded; the XHTML DOCTYPEs declare the HTML named character references.

public static class XmlDocumentParser

Methods

NameDescription
ParseDocument(Stream, XmlParserOptions?)Parses XML from the current position of a stream, determining its encoding as for byte inputs. Buffers the input and leaves the caller-owned stream open.
ParseDocument(ReadOnlySpan<byte>, XmlParserOptions?)Parses XML bytes, determining the encoding from the byte order mark, byte signature and XML declaration, or UTF-8 by default. Throws XmlException for malformed bytes, conflicting encodings or invalid XML.
ParseDocument(string, XmlParserOptions?)Parses an XML document. Throws XmlException when the document is not namespace-well-formed. The document has no browsing context: use BrowsingContext.Navigate to load a document in a browsing context.
ParseDocumentAsync(Stream, XmlParserOptions?, CancellationToken)Asynchronously reads XML from the current position of a stream and waits until the parser has finished. Buffers the input and leaves the caller-owned stream open. Cancellation interrupts reading and waiting for the parser.
ParseDocumentAsync(string, XmlParserOptions?, CancellationToken)Parses an XML document, and waits until the parser has finished: while the parser waits for a script, the tasks of the DomEventLoop of the browsing context run. Throws XmlException when the document is not namespace-well-formed (before the parser waits for a script; afterwards, the document shows the error).

ParseDocument overloads

ParseDocument(Stream, XmlParserOptions?)

XmlDocumentParser.cs

Parses XML from the current position of a stream, determining its encoding as for byte inputs. Buffers the input and leaves the caller-owned stream open.

public static Document ParseDocument(Stream stream, XmlParserOptions? options = null)
Parameters
stream Stream
options XmlParserOptions?
Returns

Document

ParseDocument(ReadOnlySpan<byte>, XmlParserOptions?)

XmlDocumentParser.cs

Parses XML bytes, determining the encoding from the byte order mark, byte signature and XML declaration, or UTF-8 by default. Throws XmlException for malformed bytes, conflicting encodings or invalid XML.

public static Document ParseDocument(ReadOnlySpan<byte> xml, XmlParserOptions? options = null)
Parameters
xml ReadOnlySpan<byte>
options XmlParserOptions?
Returns

Document

ParseDocument(string, XmlParserOptions?)

XmlDocumentParser.cs

Parses an XML document. Throws XmlException when the document is not namespace-well-formed. The document has no browsing context: use BrowsingContext.Navigate to load a document in a browsing context.

public static Document ParseDocument(string xml, XmlParserOptions? options = null)
Parameters
xml string
options XmlParserOptions?
Returns

Document

ParseDocumentAsync overloads

ParseDocumentAsync(Stream, XmlParserOptions?, CancellationToken)

XmlDocumentParser.cs

Asynchronously reads XML from the current position of a stream and waits until the parser has finished. Buffers the input and leaves the caller-owned stream open. Cancellation interrupts reading and waiting for the parser.

net10.0

public static Task<Document> ParseDocumentAsync(Stream stream, XmlParserOptions? options = null, CancellationToken cancellationToken = default)

net11.0

public static Task<Document> ParseDocumentAsync(Stream stream, XmlParserOptions? options = null, CancellationToken cancellationToken = default)
Parameters
stream Stream
options XmlParserOptions?
cancellationToken CancellationToken
Returns

Task<Document>

ParseDocumentAsync(string, XmlParserOptions?, CancellationToken)

XmlDocumentParser.cs

Parses an XML document, and waits until the parser has finished: while the parser waits for a script, the tasks of the DomEventLoop of the browsing context run. Throws XmlException when the document is not namespace-well-formed (before the parser waits for a script; afterwards, the document shows the error).

net10.0

public static Task<Document> ParseDocumentAsync(string xml, XmlParserOptions? options = null, CancellationToken cancellationToken = default)

net11.0

public static Task<Document> ParseDocumentAsync(string xml, XmlParserOptions? options = null, CancellationToken cancellationToken = default)
Parameters
xml string
options XmlParserOptions?
cancellationToken CancellationToken
Returns

Task<Document>