我有一个XML文件和一个读取内容的库(我无权访问)。遗憾的是,该库返回XML文件内容的“扁平”版本,从而删除了XML文件包含的“深度”信息。
例如,此xml文件具有以下“条目”。
<msg>
<type 0>
<struct nelem=2>
<type 1>
<type 2>
</struct>
<type 3>
<struct nelem=3>
<type 4>
<struct nelem=1>
<type 5>
</struct>
<type 6>
</struct>
</msg>
将通过Entry getNextElement()
方法返回
type 0,
struct(elem_num=2),
type 1,
type 2,
type 3,
struct(elem_num=3),
type 4,
struct(elem_num=1),
type 5,
type 6,
我保存在std::vector<entries>
。
所以我有重建XML结构的必要信息。问题是什么更合适,以及如何将索引信息附加到“条目”结构。
我正在考虑附加一个包含深度信息的索引(groupID),如下所示:
<msg>
<type 0> 1
<struct nelem=2> 2
<type 1> 2.1
<type 2> 2.2
</struct>
<type 3> 3
<struct nelem=3> 4
<type 4> 4.1
<struct nelem=1> 4.2
<type 5> 4.2.1
</struct>
<type 6> 4.3
</struct>
</msg>
我还想实现一个请求机制来询问这些条目的特定组。如果我要求“2”,我应该得到“2.1”和2.2“返回。同样当我要求”4.2“我应该得到”4.2.1“返回。 或多或少该方法应具有以下声明
vector<entries> getGroupOfEntries(const groupID);
我不确定如何实现groupID以便能够最终使用std::map<groupID, entry*>
。当深度可变时,有没有办法做到这一点?是否存在一种我不知道的完全不同的方法?
谢谢你的帮助