# HG changeset patch # User František Kučera # Date 1607195847 -3600 # Node ID 84ff7c97bfdc586ac00b5d44ffc81f1cc0130673 # Parent 0e8a58946c48c9f9d6a106dce2d771437cb44319 add --parser-option 'root-name' 'custom-root-element-name' diff -r 0e8a58946c48 -r 84ff7c97bfdc src/XMLDocumentConstructor.h --- a/src/XMLDocumentConstructor.h Sat Nov 28 23:52:01 2020 +0100 +++ b/src/XMLDocumentConstructor.h Sat Dec 05 20:17:27 2020 +0100 @@ -42,6 +42,7 @@ MAP_KEY }; + std::string rootName = "yaml"; xmlpp::Element* current; std::vector mode; @@ -51,7 +52,7 @@ *length = input->gcount(); return (input->good() || input->eof()) ? 1 : 0; } - + /** * Both YAML and XML strings are in UTF-8. */ @@ -77,12 +78,14 @@ virtual ~XMLDocumentConstructor() { yaml_parser_delete(&yamlParser); } - + void setOption(const std::string& uri, const std::string& value) { + if (uri == "root-name") rootName = value; + else throw std::invalid_argument(std::string("Invalid parser option: „") + uri + "“ with value: „" + value + "“"); } void process() { - current = parser->get_document()->create_root_node("yaml"); + current = parser->get_document()->create_root_node(rootName); mode.push_back(Mode::ROOT); std::string itemName;