I have a XML file might contain thousands of nodes like below.
<?xml version="1.0" encoding="utf-8"?>
<root>
<node>
<id>0</id>
<value>data</value>
</node>
<node>
<id>1</id>
<value>data</value>
</node>
<node>
<id>2</id>
<value>data</value>
</node>
</<root>
Each node has its "id" which guarantees be not duplicated to each other and possibly there are gaps between them. My question is what is most efficient way by using boost to search a certain node by using node's id?
Thanks.
UPDATE This is the way I did
property_tree::wptree ptree; // has been loaded somewhere
auto nodes = ptree.get_child(L"root");
bool bFound = false;
for (auto& itr : nodes)
{
auto & rec = itr.second;
int id = rec.get<int>(L"id", -1);
if (id == nodeId)
{
bFound = true;
// found it
// get other values
break;
}
}
I do not think scanning whole the file to find an item is efficient.