Skip to content

Defined in header <fkYAML/node.hpp>

fkyaml::basic_node::get_resolved_tag_name

std::string get_resolved_tag_name() const;

Gets a resolved tag name associated to the YAML node.
Some tag name must be set before calling this API.
Call has_tag_name to see if the node has any tag name beforehand.
If no tag name has been set, an fkyaml::exception will be thrown.

If the target node has a tag !!str, the returned value would be tag:yaml.org,2002:str.
This is because !! is the secondary tag handle and resolved to tag:yaml.org,2002: by default.
See https://yaml.org/spec/1.2.2/#6821-tag-handles for more details on the tag handles.

If the target node has a verbatim tag !<...>, this method returns the ... part
as the YAML specification states at https://yaml.org/spec/1.2.2/#691-node-tags.

Return Value

The tag name associated to the node.

Examples

Example
#include <iostream>
#include <fkYAML/node.hpp>

int main() {
    // create a YAML node.
    fkyaml::node n = "foo";

    // try to get a tag name before any tag name has been set.
    try {
        std::cout << n.get_resolved_tag_name() << std::endl;
    }
    catch (const fkyaml::exception& e) {
        std::cout << e.what() << std::endl;
    }

    // The tag name (!!str) is set during deserialization.
    n = fkyaml::node::deserialize("- !!str foo");
    std::cout << n.at(0).get_resolved_tag_name() << std::endl;

    // "%TAG" directive changes the prefix.
    std::string input = "%TAG !! tag:example.com,2026:\n"
                        "---\n"
                        "- !!str foo\n";
    n = fkyaml::node::deserialize(input);
    std::cout << n.at(0).get_resolved_tag_name() << std::endl;

    // You can also set a tag name manually.
    n = "foo";
    n.add_tag_name("!!str");
    std::cout << n.get_resolved_tag_name() << std::endl;

    return 0;
}

output:

No tag name has been set.
tag:yaml.org,2002:str
tag:example.com,2026:str
tag:yaml.org,2002:str

See Also