YAML directives are special instructions that provide metadata or processing information for YAML processors. They appear at the beginning of a YAML document and influence how the document is interpreted.
Directives serve several important functions in YAML:
YAML directives always start with a percent sign (%) and must appear at the top of the document, before any content. They are followed by a space and then the directive name.
%YAML 1.2
%TAG !yaml! tag:yaml.org,2002:
---
# Document content starts here
The YAML version directive specifies which version of YAML the document uses. It's crucial for ensuring compatibility with different YAML processors.
%YAML 1.2
---
key: value
The TAG directive is used to define shorthand notations for URI prefixes. This is particularly useful when working with custom data types or when referencing external schemas.
%TAG !xs! http://www.w3.org/2001/XMLSchema#
---
date: !xs!date 2023-05-15
When working with YAML directives, keep the following points in mind:
Understanding YAML directives is crucial for advanced YAML usage, especially when dealing with complex data structures or integrating with systems that require specific YAML configurations. For more information on related topics, explore YAML Tags and YAML Version Compatibility.