YamlDocument Class
Definition
Represents a parsed, read-only YAML document as an immutable tree of YamlElement views over a flat, index-linked node store, in the manner of System.Text.Json.JsonDocument.
public sealed class YamlDocument : IDisposable
- Inheritance
-
YamlDocument
- Implements
- Inherited Members
- Extension Methods
Remarks
The document materializes a single YAML document from its source. Element views are lightweight structs that remain valid until the document is disposed. The type is not thread-safe for concurrent disposal with reads.
Properties
RootElement
Gets the root element of the document.
public YamlElement RootElement { get; }
Property Value
- YamlElement
The element view onto the document root.
Methods
Dispose()
Releases the resources held by the document and invalidates its element views.
public void Dispose()
Parse(ReadOnlySpan<byte>)
Parses a YAML document from UTF-8 source.
public static YamlDocument Parse(ReadOnlySpan<byte> utf8Yaml)
Parameters
utf8YamlReadOnlySpan<byte>The UTF-8 encoded YAML source.
Returns
- YamlDocument
The parsed document.
Exceptions
- YamlFormatException
The source is not valid YAML.
Parse(ReadOnlySpan<byte>, YamlDocumentOptions)
Parses a YAML document from UTF-8 source using the specified options.
public static YamlDocument Parse(ReadOnlySpan<byte> utf8Yaml, YamlDocumentOptions options)
Parameters
utf8YamlReadOnlySpan<byte>The UTF-8 encoded YAML source.
optionsYamlDocumentOptionsThe parsing options.
Returns
- YamlDocument
The parsed document.
Exceptions
- YamlFormatException
The source is not valid YAML.
Parse(string)
Parses a YAML document from a string.
public static YamlDocument Parse(string yaml)
Parameters
yamlstringThe YAML source text.
Returns
- YamlDocument
The parsed document.
Exceptions
- ArgumentNullException
yamlis null.- YamlFormatException
The source is not valid YAML.
Parse(string, YamlDocumentOptions)
Parses a YAML document from a string using the specified options.
public static YamlDocument Parse(string yaml, YamlDocumentOptions options)
Parameters
yamlstringThe YAML source text.
optionsYamlDocumentOptionsThe parsing options.
Returns
- YamlDocument
The parsed document.
Exceptions
- ArgumentNullException
yamlis null.- YamlFormatException
The source is not valid YAML.
ParseAllDocuments(ReadOnlySpan<byte>)
Parses every document in a multi-document YAML stream from UTF-8 source.
public static IReadOnlyList<YamlDocument> ParseAllDocuments(ReadOnlySpan<byte> utf8Yaml)
Parameters
utf8YamlReadOnlySpan<byte>The UTF-8 encoded YAML stream.
Returns
- IReadOnlyList<YamlDocument>
The parsed documents, in stream order.
Exceptions
- YamlFormatException
The source is not valid YAML.
ParseAllDocuments(ReadOnlySpan<byte>, YamlDocumentOptions)
Parses every document in a multi-document YAML stream from UTF-8 source using the specified options.
public static IReadOnlyList<YamlDocument> ParseAllDocuments(ReadOnlySpan<byte> utf8Yaml, YamlDocumentOptions options)
Parameters
utf8YamlReadOnlySpan<byte>The UTF-8 encoded YAML stream.
optionsYamlDocumentOptionsThe parsing options.
Returns
- IReadOnlyList<YamlDocument>
The parsed documents, in stream order.
Exceptions
- YamlFormatException
The source is not valid YAML.
ParseAllDocuments(string)
Parses every document in a multi-document YAML stream from a string.
public static IReadOnlyList<YamlDocument> ParseAllDocuments(string yaml)
Parameters
yamlstringThe YAML stream text.
Returns
- IReadOnlyList<YamlDocument>
The parsed documents, in stream order.
Exceptions
- ArgumentNullException
yamlis null.- YamlFormatException
The source is not valid YAML.
ParseAllDocuments(string, YamlDocumentOptions)
Parses every document in a multi-document YAML stream from a string using the specified options.
public static IReadOnlyList<YamlDocument> ParseAllDocuments(string yaml, YamlDocumentOptions options)
Parameters
yamlstringThe YAML stream text.
optionsYamlDocumentOptionsThe parsing options.
Returns
- IReadOnlyList<YamlDocument>
The parsed documents, in stream order.
Exceptions
- ArgumentNullException
yamlis null.- YamlFormatException
The source is not valid YAML.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |