Xml 在无限分类中的运用

本文介绍了一种使用XML存储无限分类的方法,并通过XSL转换为数据库可用的平行分类数据。此方法利用XML天然支持树状结构的特点,简化了无限分类的维护工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

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

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

Xml 分类结构文件

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

Xml 分类运算结果文件
None.gif<Categorys>
None.gif    
<Category ID="1" RootID="1" ParentID="0" Depth="0" ChildCount="6" ParentList="" ChildList="3,5" Sort="1"/>
None.gif    
<Category ID="3" RootID="1" ParentID="1" Depth="1" ChildCount="2" ParentList="1" ChildList="4" Sort="2"/>
None.gif    
<Category ID="4" RootID="1" ParentID="3" Depth="2" ChildCount="1" ParentList="1,3" ChildList="7" Sort="3"/>
None.gif    
<Category ID="7" RootID="1" ParentID="4" Depth="3" ChildCount="0" ParentList="1,3,4" ChildList="" Sort="4"/>
None.gif    
<Category ID="5" RootID="1" ParentID="1" Depth="1" ChildCount="2" ParentList="1" ChildList="6" Sort="5"/>
None.gif    
<Category ID="6" RootID="1" ParentID="5" Depth="2" ChildCount="1" ParentList="1,5" ChildList="8" Sort="6"/>
None.gif    
<Category ID="8" RootID="1" ParentID="6" Depth="3" ChildCount="0" ParentList="1,5,6" ChildList="" Sort="7"/>
None.gif    
<Category ID="2" RootID="2" ParentID="0" Depth="0" ChildCount="0" ParentList="" ChildList="" Sort="8"/>
None.gif
</Categorys>
None.gif

转载于:https://www.cnblogs.com/slightboy/archive/2006/05/19/404752.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值