У меня есть фрагмент кода, который выполняет итерацию над деревом свойств boost (XML).
Мне нужен ptree текущего узла, а не дочерние узлы узла.Получение ptree из boost :: property_tree :: ptree :: iterator
ОБНОВЛЕНИЕ
XML-дерево
<node id="A.html">
<subnode> child A1 </subnode>
<subnode> child A2 </subnode>
</node>
<node id="B.html">
<subnode> child B1 </subnode>
<subnode> child B2 </subnode>
</node>
itteration код
void parse_tree(ptree& pt, std::string key)
{
string nkey;
if (!key.empty())
nkey = key + ".";
ptree::const_iterator end = pt.end();
for(ptree::iterator it = pt.begin(); it != end; ++it){
//if the node's id is a .html filname, save the node to file
string id = it->second.get("<xmlattr>.id","");
if(id.find("B.html") != std::string::npos){ //Let's just test for "B.html"
write_xml("test.html", pt); //saves entire tree
write_xml("test.html", it->second); //saves only children of the node
}
parse_tree(it->second, nkey + it->first); //recursion
}
}
Результаты использованием write_xml ("test.html", Pt)
(Мы получаем все дерево, мы хотим только узел)
<node id="A.html">
<subnode> child A1 </subnode>
<subnode> child A2 </subnode>
</node>
<node id="B.html">
<subnode> child B1 </subnode>
<subnode> child B2 </subnode>
</node>
Результаты с использованием write_xml ("test.html", it-> второй)
(У нас нет родителей узел .. только дочерние узлы)
<subnode> child B1 </subnode>
<subnode> child B2 </subnode>
желаемого результата
(Мы хотим, чтобы узел, и это дети, .. как так)
<node id="B.html">
<subnode> child B1 </subnode>
<subnode> child B2 </subnode>
</node>
Получение значений не мой вопрос .. мне нужно Ptree текущего itteration .. node.second обеспечивает Ptree дочерних узлов .. I нужен родительский ptree этих дочерних узлов ... Мне нужно что-то вроде 'boost :: property_tree :: ptree MyPtree = node.second.get_parent();' или что-то подобное.Спасибо – aquawicket
Это должен был быть ваш вопрос тогда :) Обновлен ответ. – sehe
жаль, что так расплывчато. Я обновил, чтобы полностью показать, с чем имею дело. И я очень благодарю вас за помощь :) – aquawicket