64,642
社区成员
发帖
与我相关
我的任务
分享
void CConfigParser::reload()
{
XercesDOMParser xmlParser;
DOMDocument* xmlDoc = NULL;
DOMNode* xmlRoot = NULL;
bool IsFirst = true;
CScopeLock sl(m_FileMutex);
xmlParser.parse(m_sConfigFile.c_str());
if(NULL == (xmlDoc = xmlParser.getDocument()))
{
_throwfmt(__FILE__, __LINE__, errno, "加载配置文件失败:%s", m_sConfigFile.c_str());
}
if(NULL == (xmlRoot = xmlDoc->getDocumentElement()))
{
_throwfmt(__FILE__, __LINE__, errno, "取配置文件根结点失败:%s", m_sConfigFile.c_str());
}
m_ConfigMap.clear();
if (xmlRoot->getNodeType() == DOMNode::ELEMENT_NODE)
{
for (DOMNode * nodeOption = xmlRoot->getFirstChild();
nodeOption != 0; nodeOption = nodeOption->getNextSibling())
{
if (nodeOption->getNodeType() == DOMNode::ELEMENT_NODE
&& 0 == strcasecmp("option", XmlCh2Char(nodeOption->getNodeName()).get())
&& nodeOption->hasAttributes())
{
DOMNode* xmlNode = NULL;
if(NULL == (xmlNode = nodeOption->getAttributes()->getNamedItem(Char2XmlCh("name").get())))
{
continue;
}
string sName = trim(XmlCh2Char(xmlNode->getNodeValue()).get());
if (sName.empty())
{
continue;
}
string sValue = trim(XmlCh2Char(nodeOption->getTextContent()).get());
if (sValue.empty())
{
continue;
}
m_ConfigMap[sName] = sValue;
if(IsFirst)
{
IsFirst = false;
}
}
}
}
}