Ignore:
Timestamp:
Nov 4, 2010, 8:50:17 PM (14 years ago)
Author:
Torben Dannhauer
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • osgVisual/src/util/visual_util.cpp

    r144 r146  
    2525util::~util(void)
    2626{
     27}
     28
     29xmlNode* util::getSceneryXMLConfig(std::string configFilename, xmlDoc*& doc)
     30{
     31        doc = NULL;
     32        xmlNode *root_element = NULL;
     33
     34        // Check for valid parameters
     35        if(configFilename == "")
     36        {
     37                OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : Invalid Configuration Filename!" << std::endl;
     38                return NULL;
     39        }
     40
     41        // It is a valid XML document?
     42        doc = xmlReadFile(configFilename.c_str(), NULL, 0);     
     43        if (doc == NULL)
     44        {
     45                OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : " << configFilename << " is not a valid XML file!" << std::endl;
     46                return NULL;
     47        }
     48
     49        //  Get the root element node
     50        root_element = xmlDocGetRootElement(doc);
     51
     52        // If file is a valid osgVisual config file, check all the root xml node and all of it's children of osgvisualconfiguration for the specified module
     53        xmlNode* tmpNode = checkXMLNodeChildrenForScenery(root_element);
     54
     55        if( !tmpNode ) // if no valid node was found: clena up. Otherwise: the caller has to clean up.
     56        {
     57                xmlFreeDoc(doc);        // free the document
     58                xmlCleanupParser();     // Free the global variables that may have been allocated by the parser.
     59                return NULL;
     60        }
     61        else
     62                return tmpNode;
     63}
     64
     65xmlNode* util::checkXMLNodeChildrenForScenery(xmlNode* node)
     66{
     67        for (xmlNode *cur_node = node; cur_node; cur_node = cur_node->next)     // iterate through all elements
     68        {
     69                // Is the node the one we are searching for?
     70                if (cur_node->type == XML_ELEMENT_NODE)
     71                {
     72                        std::string node_name=reinterpret_cast<const char*>(cur_node->name);
     73                        if (node_name == "scenery")
     74                        {
     75                                OSG_DEBUG << "XML node scenery found" << std::endl;
     76                                return cur_node;
     77                        }
     78                        else    // Otherwise: check its children..
     79                        {
     80                                xmlNode* tmp_XmlNode = checkXMLNodeChildrenForScenery(cur_node->children);
     81                                if(tmp_XmlNode)
     82                                        return tmp_XmlNode;
     83                        }
     84                }       // IF NODE TYPE = ELEMENT END
     85
     86                // Proceed with next node in this loop.
     87        }
     88        return NULL;
    2789}
    2890
     
    100162                // Proceed with next node in this loop.
    101163        }
     164        return NULL;
    102165}
    103166
Note: See TracChangeset for help on using the changeset viewer.