From b3b87842b15352dcfc6cd3ff6a2c66cda4696d9b Mon Sep 17 00:00:00 2001 From: mfranz Date: Wed, 6 Jun 2007 21:18:25 +0000 Subject: [PATCH] savexml: analog to loadxml, if no is given, save file contents from the argument tree's node. That way one doesn't have to plug a temporary branch into the main tree. --- src/Main/fg_commands.cxx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 3ecb7591c..b5341f8f5 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -1352,6 +1352,8 @@ do_load_xml_to_proptree(const SGPropertyNode * arg) * XML file * @param sourcenode a string pointing to a location within the property tree * where to find the nodes that should be written recursively into an XML file + * @param data if no sourcenode is given, then the file contents are taken from + * the argument tree's "data" node. * * TODO: * deal with already existing filenames, optionally return error/success @@ -1364,11 +1366,18 @@ do_load_xml_to_proptree(const SGPropertyNode * arg) static bool do_save_xml_from_proptree(const SGPropertyNode * node) { - //TODO: do Parameter validation ! SGPropertyNode * sourcenode; - sourcenode = fgGetNode(node->getNode("sourcenode")->getStringValue(),true); + if (node->hasValue("sourcenode")) + sourcenode = fgGetNode(node->getStringValue("sourcenode"), true); + else if (node->hasValue("data")) + sourcenode = const_cast(node)->getNode("data"); + else + return false; + + const char *filename = node->getStringValue("filename", 0); + if (!filename) + return false; - const char *filename = node->getNode("filename")->getStringValue(); try { writeProperties (filename, sourcenode, true); } catch (const sg_exception &e) { -- 2.39.5