首页 > 其他分享 >boost解析多节点的XML文件的常用代码范式

boost解析多节点的XML文件的常用代码范式

时间:2022-11-28 14:57:58浏览次数:40  
标签:XML std 范式 auto ptree return boost singleBond

    std::string parseBond(std::string& fileName)
    {
        boost::property_tree::ptree ptree_root;
        try {
            boost::property_tree::read_xml(fileName, ptree_root);
        }
        catch (std::exception& e)
        {
            return e.what();
        };

        auto Bonds = ptree_root.get_child("IMIXML");
        BOOST_FOREACH(auto &Bond, Bonds)
        {
            CBond singleBond;
            memset(&singleBond, 0, sizeof(singleBond));
            try {
            getSingleBond(Bond.second, &singleBond);
            auto pOld = memdb->m_BondFactory->getByBondIDIndex(singleBond.BondID, singleBond.MarketType);
            memdb->m_BondFactory->addOrUpdate(pOld, &singleBond, 0);
            }
            catch (std::exception& e)
            {
                return e.what();
            }
        }
        return "";
    }

重点注意看getChild和for循环遍历

标签:XML,std,范式,auto,ptree,return,boost,singleBond
From: https://www.cnblogs.com/huangshiyi/p/16932182.html

相关文章