From: mzn Date: Fri, 19 Oct 2007 05:48:43 +0000 (+0000) Subject: Use xmlNodeGetContent(...) method instead of getting content field of xmlNode. X-Git-Tag: V4_1_0a2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=90f79976a01f1ea7a9fff9fd49aaa3f05579cff2;p=modules%2Fkernel.git Use xmlNodeGetContent(...) method instead of getting content field of xmlNode. --- diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_Handler.cxx b/src/ModuleCatalog/SALOME_ModuleCatalog_Handler.cxx index 3c7fa944d..be66d8ee0 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_Handler.cxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_Handler.cxx @@ -140,9 +140,8 @@ void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) // Get the document root node xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc); - aCurNode = aCurNode->xmlChildrenNode; - + // Processing the document nodes while(aCurNode != NULL) { @@ -162,16 +161,26 @@ void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) while(aCurSubSubNode != NULL) { // Tag test_path_prefix_name - if ( !xmlStrcmp(aCurSubSubNode->name, (const xmlChar*)test_path_prefix_name) ) - _pathPrefix.path = (const char*)aCurSubSubNode->content; + if ( !xmlStrcmp(aCurSubSubNode->name, (const xmlChar*)test_path_prefix_name) ) { + xmlChar* aPath = xmlNodeGetContent(aCurSubSubNode); + if (aPath != NULL) { + _pathPrefix.path = (const char*)aPath; + xmlFree(aPath); + } + } // Tag test_computer_list if ( !xmlStrcmp(aCurSubSubNode->name, (const xmlChar*)test_computer_list) ) { xmlNodePtr aComputerNode = aCurSubSubNode->xmlChildrenNode; while (aComputerNode != NULL) { // Tag test_computer_name - if ( !xmlStrcmp(aComputerNode->name, (const xmlChar*) test_computer_name) ) - _pathPrefix.listOfComputer.push_back((const char*)aComputerNode->content); + if ( !xmlStrcmp(aComputerNode->name, (const xmlChar*) test_computer_name) ) { + xmlChar* aCompName = xmlNodeGetContent(aComputerNode); + if (aCompName != NULL) { + _pathPrefix.listOfComputer.push_back((const char*)aCompName); + xmlFree(aCompName); + } + } aComputerNode = aComputerNode->next; } @@ -210,12 +219,19 @@ void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) xmlNodePtr aComponentSubNode = aComponentNode->xmlChildrenNode; while(aComponentSubNode != NULL) { - std::string aContent = (const char*)aComponentSubNode->content; + xmlChar* aNodeContent = xmlNodeGetContent(aComponentSubNode); + + if (aNodeContent == NULL) { + aComponentSubNode = aComponentSubNode->next; + continue; + } + + std::string aContent = (const char*)aNodeContent; // Tag test_component_name if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_name) ) _aModule.name = aContent; - + // Tag test_component_username if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_component_username) ) _aModule.username = aContent; @@ -286,6 +302,8 @@ void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_constraint) ) _aModule.constraint = aContent; + xmlFree(aNodeContent); + // Process tag test_interface_list: if ( !xmlStrcmp(aComponentSubNode->name, (const xmlChar*)test_interface_list) ) { @@ -293,8 +311,13 @@ void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) xmlNodePtr aSubNode = aComponentSubNode->xmlChildrenNode; while(aSubNode != NULL) { // Tag test_interface_name - if ( !xmlStrcmp(aSubNode->name, (const xmlChar*)test_interface_name) ) - _aInterface.name = (const char*)aSubNode->content; + if ( !xmlStrcmp(aSubNode->name, (const xmlChar*)test_interface_name) ) { + xmlChar* anInterfaceName = xmlNodeGetContent(aSubNode); + if (anInterfaceName != NULL) { + _aInterface.name = (const char*)anInterfaceName; + xmlFree(anInterfaceName); + } + } // Tag test_service_list if ( !xmlStrcmp(aSubNode->name, (const xmlChar*)test_service_list) ) { @@ -305,17 +328,25 @@ void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) if ( !xmlStrcmp(aCompServiceNode->name, (const xmlChar*)test_interface_name) ) { xmlNodePtr aCompServiceSubNode = aCompServiceNode->xmlChildrenNode; while(aCompServiceSubNode != NULL) { - // Tag test_service_name - if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_service_name) ) - _aService.name = (const char*)aCompServiceSubNode->content; - // Tag test_defaultservice - if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_defaultservice) ) - _aService.byDefault = (const char*)aCompServiceSubNode->content; + xmlChar* aCompServiceData = xmlNodeGetContent(aCompServiceSubNode); + + if ( aCompServiceData != NULL) { + + // Tag test_service_name + if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_service_name) ) + _aService.name = (const char*)aCompServiceData; + + // Tag test_defaultservice + if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_defaultservice) ) + _aService.byDefault = (const char*)aCompServiceData; + + // Tag test_typeofnode + if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_typeofnode) ) + _aService.typeOfNode = (const char*)aCompServiceData; - // Tag test_typeofnode - if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_typeofnode) ) - _aService.typeOfNode = (const char*)aCompServiceSubNode->content; + xmlFree(aCompServiceData); + } // Tag test_inParameter_list if ( !xmlStrcmp(aCompServiceSubNode->name, (const xmlChar*)test_inParameter_list) ) { @@ -330,14 +361,21 @@ void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode; while(aParamItemNode != NULL) { - - // Tag test_inParameter_name - if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_name) ) - _inParam.name = (const char*)aParamItemNode->content; - - // Tag test_inParameter_type - if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_type) ) - _inParam.type = (const char*)aParamItemNode->content; + + xmlChar* aParamData = xmlNodeGetContent(aParamItemNode); + + if (aParamData != NULL) { + + // Tag test_inParameter_name + if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_name) ) + _inParam.name = (const char*)aParamData; + + // Tag test_inParameter_type + if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inParameter_type) ) + _inParam.type = (const char*)aParamData; + + xmlFree(aParamData); + } aParamItemNode = aParamItemNode->next; } @@ -368,14 +406,21 @@ void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode; while(aParamItemNode != NULL) { - - // Tag test_outParameter_name - if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_name) ) - _outParam.name = (const char*)aParamItemNode->content; - - // Tag test_outParameter_type - if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_type) ) - _outParam.type = (const char*)aParamItemNode->content; + + xmlChar* anOutParamData = xmlNodeGetContent(aParamItemNode); + + if (anOutParamData != NULL) { + + // Tag test_outParameter_name + if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_name) ) + _outParam.name = (const char*)anOutParamData; + + // Tag test_outParameter_type + if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outParameter_type) ) + _outParam.type = (const char*)anOutParamData; + + xmlFree(anOutParamData); + } aParamItemNode = aParamItemNode->next; } @@ -407,17 +452,24 @@ void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode; while(aParamItemNode != NULL) { - // Tag test_inDataStreamParameter_name - if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_name) ) - _inDataStreamParam.name = (const char*)aParamItemNode->content; - - // Tag test_inDataStreamParameter_type - if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_type) ) - _inDataStreamParam.type = (const char*)aParamItemNode->content; - - // Tag test_inDataStreamParameter_dependency - if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_dependency) ) - _inDataStreamParam.dependency = (const char*)aParamItemNode->content; + xmlChar* inDataStreamParamData = xmlNodeGetContent(aParamItemNode); + + if (inDataStreamParamData != NULL) { + + // Tag test_inDataStreamParameter_name + if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_name) ) + _inDataStreamParam.name = (const char*)inDataStreamParamData; + + // Tag test_inDataStreamParameter_type + if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_type) ) + _inDataStreamParam.type = (const char*)inDataStreamParamData; + + // Tag test_inDataStreamParameter_dependency + if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_inDataStreamParameter_dependency) ) + _inDataStreamParam.dependency = (const char*)inDataStreamParamData; + + xmlFree(inDataStreamParamData); + } aParamItemNode = aParamItemNode->next; } @@ -450,18 +502,25 @@ void SALOME_ModuleCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) xmlNodePtr aParamItemNode = aParamNode->xmlChildrenNode; while(aParamItemNode != NULL) { - // Tag test_outDataStreamParameter_name - if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_name) ) - _outDataStreamParam.name = (const char*)aParamItemNode->content; - - // Tag test_outDataStreamParameter_type - if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_type) ) - _outDataStreamParam.type = (const char*)aParamItemNode->content; - - // Tag test_outDataStreamParameter_dependency - if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_dependency) ) - _outDataStreamParam.dependency = (const char*)aParamItemNode->content; + xmlChar* outDataStreamParamData = xmlNodeGetContent(aParamItemNode); + if (outDataStreamParamData != NULL) { + + // Tag test_outDataStreamParameter_name + if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_name) ) + _outDataStreamParam.name = (const char*)outDataStreamParamData; + + // Tag test_outDataStreamParameter_type + if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_type) ) + _outDataStreamParam.type = (const char*)outDataStreamParamData; + + // Tag test_outDataStreamParameter_dependency + if ( !xmlStrcmp(aParamItemNode->name, (const xmlChar*)test_outDataStreamParameter_dependency) ) + _outDataStreamParam.dependency = (const char*)outDataStreamParamData; + + xmlFree(outDataStreamParamData); + } + aParamItemNode = aParamItemNode->next; } diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx index b4d7edbd1..74640bc3c 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx @@ -45,15 +45,14 @@ static const char* SEPARATOR = "::"; static const char* OLD_SEPARATOR = ":"; -list& splitStringToList(string theString, string theSeparator) +list splitStringToList(const string& theString, const string& theSeparator) { list aList; int sepLen = theSeparator.length(); - int startPos = 0, sepPos = theString.find(theSeparator, startPos); - for ( ; (startPos < theString.size()) && (sepPos != string::npos); sepPos = theString.find(theSeparator, startPos)) + for ( ; (startPos < theString.length()) && (sepPos != string::npos); sepPos = theString.find(theSeparator, startPos)) { string anItem = theString.substr(startPos, sepPos - startPos); if (anItem.length() > 0) @@ -151,14 +150,9 @@ SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA: while(aPath.find('\"') != string::npos) aPath.erase(aPath.find('\"'), 1); - FILE* aFile = fopen(aPath.c_str(), "r"); - if (aFile != NULL) { - _parse_xml_file(aPath.c_str(), - _general_module_list, - _general_path_list); - - fclose(aFile); - } + _parse_xml_file(aPath.c_str(), + _general_module_list, + _general_path_list); } // Verification of _general_path_list content @@ -603,7 +597,8 @@ SALOME_ModuleCatalogImpl::_parse_xml_file(const char* file, if (aFile != NULL) { xmlDocPtr aDoc = xmlReadFile(file, NULL, 0); - if (aDoc != NULL) + + if (aDoc != NULL) handler->ProcessXmlDocument(aDoc); else INFOS("ModuleCatalog: could not parse file "<