导航

Tinyxml 类

Posted on 2009-03-14 00:06  My Gold  阅读(224)  评论(0)    收藏  举报

Tinyxml 是一个非常小巧的XML操作类,使用标准C++ 书写,使用非常方便。需要的可以联系我,dangde@163.com.

 

 TiXmlDocument xmldoc;
 xmldoc.LoadFile(sPath.c_str(), TIXML_ENCODING_LEGACY);
 TiXmlElement *root = xmldoc.RootElement();
 TiXmlNode *xmlnode = root->FirstChild("StdField");
 TiXmlNode *pnode = xmlnode->FirstChild();

 for (int i = 0; pnode; i++)
 {
  try
  {
   string sKey;
   string sValue;
   
   if (!pnode->ToElement()->Attribute("ID") || !pnode->ToElement()->Attribute("Name"))
   {
    cout << "TDataDict error: build standard field map,check xml file standard field index: " << i << endl;
   }
   else
   {
    sKey = pnode->ToElement()->Attribute("Name");
    sValue = string(pnode->ToElement()->Attribute("ID"));

    StdField.insert(pair<string,int>(sKey, atoi(sValue.c_str())));
   }
  }
  catch(...)
  {

     //???
  }
  
  pnode = pnode->NextSibling();
 }