//范例如下,注释随代码
#include <iostream>
#include <string>
#include <map>
using namespace std;
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string.hpp>
using namespace boost::property_tree;
typedef map<string, string> ssMap;
class CBoostXmlUtil{
public:
static ssMap* ReadXml(string& xml){
ptree oTree, oRoot;
xml_parser::read_xml(xml, oTree);
oRoot = oTree.get_child("Root");
ssMap* pConfigMap = new ssMap;
for(ptree::iterator it = oRoot.begin(); it != oRoot.end(); it++){
string strKey = it->first; boost::algorithm::trim(strKey);
ptree oNode = it->second; string strValue = oNode.data(); boost::algorithm::trim(strValue);
pConfigMap->insert(pair<string, string>(strKey, strValue));
}
return pConfigMap;