当前位置: 首页 >> 程序设计 >> 递归函数遍历XML结构源码
 

递归函数遍历XML结构源码

作者:      来源:http://blog.csdn.net/lc2236     发表时间:2007-01-10     浏览次数:      字号:    

//write by void<lc@zm.com.cn> 
//param1 xnode:the XMLDocument root node,
//param2 tnode: Tree struct 's root node
//description:  parse xml file to fill tree struct 
void FillTree(_di_IXMLNode xnode,TTreeNode *tnode)
{
 

   _di_IXMLNodeList nodes
=xnode->ChildNodes; 
   _di_IXMLNode curXnode;
   TTreeNode  
*pt=tnode;
   TTreeNode  
*pt1=tnode;

  
for(int n=0;n<nodes->Count;n++)
  
{
      curXnode
=nodes->Nodes[n];
 
if( curXnode->GetHasChildNodes() )
    
{
 
    
if(curXnode->GetIsTextElement())
      pt1
=TreeView->Items->AddChild(pt,(curXnode->GetNodeName()+" "+curXnode->GetText()) ) ;
    
else
    
{
     
if(curXnode->GetNodeName()==WideString("description" )||curXnode->GetNodeName()==(wchar_t*)("title"))
     
{
      xmlobj 
*mobj=new xmlobj;
 
      mobj
->xmlstr =curXnode->GetXML();      //
      pt1=TreeView->Items->AddChildObject(pt,string(curXnode->GetNodeName()+" type="+string(curXnode->GetNodeType())),mobj ) ;
 
     }

      
else
 
      pt1
=TreeView->Items->AddChild(pt,string(curXnode->GetNodeName()+" type="+string(curXnode->GetNodeType()))) ;
 
     }

 
    FillTree(curXnode,pt1);
   }

 
  }

}

 

编辑 webmaster

 
 
 
评论更多>>
 
 
发表
 
姓名: QQ:
性别: MSN:
E-mail: 主页:
评分: 1 2 3 4 5
评论内容:
验证码:
  
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。
  •