开发者

Managing hierarchical data in C/C++

Currently I am researching on managing hierarchical data (from XML) in C/C++. 开发者_高级运维I need to parse XML files and store them in a DB effectively, so I should be able to query the DB later on. Any suggestions on this are most welcome.

I came across Managing Hierarchical Data in MySQL. This looks good, but still wondering if there are other ways to do it.


If you read closely the document, you'll find there are 2 ways stored hierarchical data, one using a "parent_ID", another using "left_sibling_ID" & "right_sibling_ID".

I suggest use the first one:

myxmltable = {myxmltable_ID, myxmltable_parent_ID, myxmltable_otherfield_1, ...}

Additionally, you could store all your items, with an key > 0. The parent key for the root item could be 0, meaning, it has no parent. I suggest avoid using NULL, in order to make more easy to handle your D.B. and use 0 instead.


XML stores hierarchical data which does not fit well with the relational approach of SQL. I would strongly suggest you look at XPath/XQuery, which are query languages that operate on the XML directly. Qt contains an XQuery library that I've used with good results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜