一直考虑 关系型数据库 中实现无限分类的高效办法
尝试过 编码法 但发现限制颇多最终放弃了
也尝试过一般论坛使用的分类方法 但总觉得维护不是很方便
至于更高级的分类算法 限于自身数学水平有限 也就不考虑

而然想到 用 Xml 存储结构 数据库记录数据和结果
Xml 存储树型结构有着与身具来的优越性 而且这样维护 比较简单, 也不要用递归

xml 存储结构后 用 Xsl 格式化 直接得到适合数据库用的平行分类数据
然后直接入库就可以了
但还是一个小问题 就是分类一多 更新的条目就比较多了
但也可以通过判断 把更新控制在 1-2 个大类下
这样相对来说 更新条目会少点

以下是简单示例 至于 Xsl 卖个关子 保密下

Xml 分类结构文件

<?xml version="1.0" encoding="utf-8"?>
<Categorys>
  
<Category ID="1" RootID="1">
    
<Category ID="3" RootID="1">
      
<Category ID="4" RootID="1">
        
<Category ID="7" RootID="1" />
      
</Category>
    
</Category>
    
<Category ID="5" RootID="1">
      
<Category ID="6" RootID="1">
        
<Category ID="8" RootID="1" />
      
</Category>
    
</Category>
  
</Category>
  
<Category ID="2" RootID="2" />
</Categorys>

Xml 分类运算结果文件
<Categorys>
    
<Category ID="1" RootID="1" ParentID="0" Depth="0" ChildCount="6" ParentList="" ChildList="3,5" Sort="1"/>
    
<Category ID="3" RootID="1" ParentID="1" Depth="1" ChildCount="2" ParentList="1" ChildList="4" Sort="2"/>
    
<Category ID="4" RootID="1" ParentID="3" Depth="2" ChildCount="1" ParentList="1,3" ChildList="7" Sort="3"/>
    
<Category ID="7" RootID="1" ParentID="4" Depth="3" ChildCount="0" ParentList="1,3,4" ChildList="" Sort="4"/>
    
<Category ID="5" RootID="1" ParentID="1" Depth="1" ChildCount="2" ParentList="1" ChildList="6" Sort="5"/>
    
<Category ID="6" RootID="1" ParentID="5" Depth="2" ChildCount="1" ParentList="1,5" ChildList="8" Sort="6"/>
    
<Category ID="8" RootID="1" ParentID="6" Depth="3" ChildCount="0" ParentList="1,5,6" ChildList="" Sort="7"/>
    
<Category ID="2" RootID="2" ParentID="0" Depth="0" ChildCount="0" ParentList="" ChildList="" Sort="8"/>
</Categorys>
posted on 2006-05-19 23:17  jayu  阅读(484)  评论(0编辑  收藏  举报