解析iworld xml,拿到entity和visiblevolume的資料
int parseiworlds::readxml(const bpath &dir)
catch (const std::exception& e)
ptree ptchild = pt.get_child("world.levels.level.root.entity.rootarea.root.entity.entities");
for (auto& data : ptchild)
//visbilityvolume
auto visibilitycube = ptchildentity.get_child_optional("visibilitycube.root.entity.resource");
if (visibilitycube)
m_objectmap[object.name] = object;
cout << endl;
} cout << "object cnt:" << m_objectmap.size() << endl;
return 1;
}
寫入xml時候,注意使用setting引數,保證檔案內容樣式有縮排有對齊
boost::property_tree::xml_writer_settingssettings = boost::property_tree::xml_writer_make_settings('\t', 1);
//把property_tree 轉為xml檔案
write_xml(path, pt, std::locale(), settings);
void visibilityvolume::writeresourcexml(const string & path)
<?xml version="1.0" encoding="utf-8"?>
1(-50.000000,-45.000000,-50.000000,50.000000,55.000000,50.000000)520
2020
1717
3141
先讀取xml,獲得ptree,修改ptree中的節點,注意讀取的時候,read_xml引數使用trim_whitespace裁剪空格和換行
read_xml(m_iworlddir.string(), pt, boost::property_tree::xml_parser::trim_whitespace);
void parseiworlds::writeoccluid(map&iworldobj)
catch (const std::exception& e)
ptree &ptchild = pt.get_child("world.levels.level.root.entity.rootarea.root.entity.entities");
//遍歷所有items
for (auto& data : ptchild) }
//設定寫入xml檔案的格式
boost::property_tree::xml_writer_settingssettings = boost::property_tree::xml_writer_make_settings('\t', 1);
//把property_tree 轉為xml檔案
write_xml(m_iworlddir.string(), pt, std::locale(), settings);
}
Boost 解析xml 插入Item
xml格式為 xml version 1.0 encoding utf 8 config item name a desc childitem name name desc datatype string 11111 childitem childitem name subject desc dat...
boost生成xml與tinyxml之間的格式轉換
ifndef simulation structures h define simulation structures h include include boost serialization vector.hpp include boost archive xml oarchive.hpp in...
Dom解析 修改xml元素
真正的暴力派,先一口吃下,再慢慢順藤摸瓜得到全部內容.哈哈.既然吃的太猛有可能就會被撐死.解析原理 是把整個xml檔案當做乙個物件來處理,會先把整個文件讀到記憶體中.是基於樹狀的機構的.可以很方便的增加修改刪除元素等操作,但也很容易造成記憶體溢位,在安卓開發中基本不用.解析思路 獲取document...