Altova XMLSpy 2025 Professional Edition

Anchors and Aliases

Home Prev Top Next

Anchors and aliases are a YAML feature similar to XML entities. They enable you to use the same YAML data fragment multiple times in the document.

 

A data fragment is "anchored" by a string prefixed with an ampersand (&, see screenshots below). The anchored fragment can be reused at any subsequent point in the document order by "aliasing" it. An alias is the same string as that of an anchor, but preceded by an asterisk (*) instead of the ampersand. When the YAML document is parsed, the alias is replaced by the anchored fragment (in the screenshot below right, see in the blue box the data fragment that the *release alias references.

 

The screenshots below show anchors and aliases in Text View (left) and Grid View (right).

Click to expand/collapse     xsyamlanchoraliasgridview_zoom77

Note the following points about anchors and aliases in Text View and Grid View:

 

In Grid View, notice the icons for anchors and aliases.

In Grid View, to create an anchor on a key–value pair, right click either the key or the value and select Edit Anchor. If you do not enter a name for the anchor and press Enter (or click anywhere), the anchor will not be created.

To edit an anchor in Grid View, right click it and select Edit Anchor.

To delete an anchor in Grid View, right click it and select Edit Anchor, then delete the name and press Enter.

In both views, auto-completion of aliases (see the cursor entry point of the Text View screenshot above) enables you to select from anchors defined at earlier points in the document. This is particularly useful in large documents: you can scroll through the available anchors to choose the one you want.

In Grid View, hover over an alias to see the anchored data fragment, which appears in a blue box (see the Grid View screenshot above).

In both views, when the cursor is placed inside an alias, select the menu command DTD/Schema | Go to Definition to take you to the corresponding anchor. If the Grid View cell containing the anchor was collapsed, it will be expanded.

 

Note:Since Grid View Filters and Formulas are based on XQuery, they will only work in JSON-like YAML. Anchors and aliases, however, are non-JSON features and will therefore cause an XQuery error when a filter or formula is calculated.

 

© 2018-2024 Altova GmbH