TinyXml op by C++
2012-03-26 00:00
260 查看
TinyXML is a simple, small, C++ XML parser that can be easily integrated into other programs.
TinyXML SourceCode: http://sourceforge.net/projects/tinyxml/
TinyXML只需要通过first child和next sibling进行创建Dom树。然后通过用根节点的指针为起点进行遍历整棵树。
下面是一段自己操作XML的代码。(C++)
$(document).ready(function(){dp.SyntaxHighlighter.HighlightAll('code');});
原文链接:
http://blog.csdn.net/crazyjixiang/article/details/7035010
TinyXML SourceCode: http://sourceforge.net/projects/tinyxml/
TinyXML只需要通过first child和next sibling进行创建Dom树。然后通过用根节点的指针为起点进行遍历整棵树。
下面是一段自己操作XML的代码。(C++)
typedef struct QueueInfo* pQueueInfo; struct QueueInfo { int m_iQueueId; char m_chQueueIp[20]; int m_iQueuePort; vector<int> m_vctDataType; }; typedef struct ServerInfo* pServerInfo; struct ServerInfo { string m_mongoIp; int m_mongoPort; string m_mongoDBName; double m_mongoTimeout; string m_logPrefix; string m_logDir; string m_queServerIp; int m_queServerPort; int m_queServerId; int m_queServerCount; int m_queServerDid; vector<QueueInfo> m_vctQueueInfo; }; class ServerConf{ public: bool ReadXmlCfg(const char* _path, pServerInfo _pSI); };
bool ServerConf::ReadXmlCfg(const char* _path, pServerInfo _pSI) { TiXmlDocument* myDocument = new TiXmlDocument(_path); if (NULL == myDocument) { AC_ERROR("Can't init %s", _path); return false; } myDocument->LoadFile(); TiXmlElement* pRoot = myDocument->RootElement(); if (NULL == pRoot) { AC_ERROR("Can't init Xml root"); return false; } //读取MongoServer TiXmlElement* pMongo = pRoot->FirstChildElement("MongoDBServerCfg"); if(NULL == pMongo) { AC_ERROR("Can't find QueueServiceCfg"); return false; } _pSI->m_mongoIp = pMongo->Attribute("serverIp"); _pSI->m_mongoPort = atol(pMongo->Attribute("serverPort")); _pSI->m_mongoDBName = pMongo->Attribute("dbName"); _pSI->m_mongoTimeout = atol(pMongo->Attribute("timeout")); //读取QueueServer TiXmlElement* pQueues = pMongo->NextSiblingElement("QueueServerCfg"); if(NULL == pQueues) { AC_ERROR("Can't find QueueServiceCfg"); return false; } _pSI->m_queServerIp = pQueues->Attribute("serverIp"); _pSI->m_queServerPort = atol(pQueues->Attribute("serverPort")); _pSI->m_queServerId = atol(pQueues->Attribute("id")); _pSI->m_queServerCount = atol(pQueues->Attribute("count")); _pSI->m_queServerDid = atol(pQueues->Attribute("did")); /*循环取出队列配置*/ TiXmlElement* pQueueChild = pQueues->FirstChildElement("queueCfg"); while (NULL != pQueueChild) { struct QueueInfo QIobj; QIobj.m_iQueueId = atoi(pQueueChild->Attribute("id")); /*id*/ memcpy(QIobj.m_chQueueIp, pQueueChild->Attribute("ip"), strlen(pQueueChild->Attribute("ip"))); /*ip*/ QIobj.m_iQueuePort = atoi(pQueueChild->Attribute("port")); /*port*/ char* strBuf = NULL; char* strToken; const char* str = pQueueChild->Attribute("dataType"); /*dataType*/ string strDataType(str); strToken = strtok_r(&strDataType[0],",",&strBuf); while (strToken != NULL) { QIobj.m_vctDataType.push_back(atoi(strToken)); strToken = strtok_r(NULL,",",&strBuf); } _pSI->m_vctQueueInfo.push_back(QIobj); pQueueChild = pQueueChild->NextSiblingElement("queueCfg"); } delete myDocument; return true; }
$(document).ready(function(){dp.SyntaxHighlighter.HighlightAll('code');});
原文链接:
http://blog.csdn.net/crazyjixiang/article/details/7035010
相关文章推荐
- C++ tinyxml解析小试及VC6.0调试中遇到的问题
- C++中用TinyXML对XML文件进行解析
- C++通过TinyXML类库读写XML文件
- C++&nbsp;XML解析之TinyXML篇【转】
- C++之tinyXML使用
- C++之tinyXML使用
- C++ TinyXml操作(含源码下载)
- C++ XML解析之TinyXML篇
- C++之tinyXML使用
- (转载)C++之tinyXML使用
- C++它tinyXML使用
- C++之tinyXML使用
- C++解析XML-TinyXml
- tinyxml非常好的实例 --c++解析XML
- C++ tinyxml使用
- C++之tinyXML使用
- C++提取xml文件(使用开源工具类tinyxml)
- TinyXML(C++)
- c++ tinyxml
- C++ tinyxml的编译及简单使用方法