add --parser-option 'root-name' 'custom-root-element-name' v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 05 Dec 2020 20:17:27 +0100
branchv_0
changeset 26 84ff7c97bfdc
parent 25 0e8a58946c48
child 27 d6d710336e7c
add --parser-option 'root-name' 'custom-root-element-name'
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> 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;