Table of Contents

Bodu.Text.Yaml.Nodes Namespace

Package

Bodu.Text.Yaml.Nodes

Purpose

Bodu.Text.Yaml.Nodes is the mutable document object model of Bodu.Text.Yaml, shaped after System.Text.Json.Nodes. Parse YAML text into an editable tree, build one from scratch, change it, and write it back through the Utf8YamlWriter. For read-only inspection with fewer allocations, use the sibling Bodu.Text.Yaml.Document tier; for typed binding, use the YamlSerializer. A member typed YamlNode binds through the serializer's DOM bridge.

Key types

  • YamlNode - abstract base: Parse, AsObject / AsArray / AsValue, string and integer indexers, WriteTo, and ToYamlString.
  • YamlObject - a mapping node keyed by string, with Add / Remove / TryGetValue and an indexer.
  • YamlArray - a sequence node with Add / Remove / RemoveAt and an integer indexer.
  • YamlValue - a scalar leaf (string, integer, float, or boolean), created via Create and read via GetValue<T>.

Example

using Bodu.Text.Yaml.Nodes;

YamlObject root = YamlNode.Parse("host: localhost\nport: 8080\n")!.AsObject();
root["port"] = YamlValue.Create(9090);
root.Add("tls", YamlValue.Create(true));

string yaml = root.ToYamlString();

Notes

  • Explicit scalar creation. Unlike the TOML and Bencode node DOMs there are no implicit conversions; wrap scalars with YamlValue.Create so the value kind is unambiguous under YAML's implicit typing.
  • Presentation is normalized. Comments, anchors, aliases, and the original scalar styles are not retained; ToYamlString re-emits the tree in block style.
  • See also: the Bodu.Text.Yaml introduction and the Using YAML guide (Pattern 4 - Edit a document with the mutable DOM).

Classes

YamlArray

Represents a mutable YAML sequence node whose elements are YamlNode values.

YamlNode

Represents a node in a mutable YAML document object model, in the manner of System.Text.Json.Nodes.JsonNode.

YamlObject

Represents a mutable YAML mapping node whose entries preserve insertion order.

YamlValue

Represents a scalar node in a mutable YAML document object model.