您的位置:程序门 -> .net技术 -> vb.net



vb.net 读取xml 生成  treeview 问题,100分,在线等给分


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


vb.net 读取xml 生成 treeview 问题,100分,在线等给分[已结贴,结贴人:fivestars]
发表于:2007-03-27 16:28:24 楼主
<?xml   version= "1.0 "   encoding= "gb2312 "?>
<treenodes>
<treenode   text= "aa ">
    <treenode   text= "a1 "   />
</treenode>      
<treenode   text= "bb ">
    <treenode   text= "b1 "   />  
    <treenode   text= "b2 "   />  
</treenode>
</treenodes>

希望生成  
aa
    a1
bb
    b1
    b2
的树形结构  
在线等,解决给分
发表于:2007-03-27 16:37:461楼 得分:80
dim   document   as   new   system.xml.xmldatadocument()       document.load( "../contacts.xml ")       populatetreecontrol(document.documentelement,   _               treeview1.nodes)

private   sub   populatetreecontrol(   _             byval   document   as   system.xml.xmlnode,   _             byval   nodes   as   _               system.windows.forms.treenodecollection)                  
dim   node   as   system.xml.xmlnode            
for   each   node   in   document.childnodes                  
'   if   the   element   has   a   value,   display   it;                    
'   otherwise   display   the   first   attribute                    
'   (if   there   is   one)   or   the   element   name                    
'   (if   there   isn 't)                  
dim   [text]   as   string                  
if   node.value   <>   nothing   then                        
[text]   =   node.value                  
else                        
if   not   node.attributes   is   nothing   and   node.attributes.count   >   0   then                              
[text]   =   node.attributes(0).value                        
else                              
[text]   =   node.name                        
end   if                  
end   if                        
dim   new_child   as   new   treenode([text])                   nodes.add(new_child)                   populatetreecontrol(node,   new_child.nodes)            
next   node      
end   sub
发表于:2007-03-27 16:38:172楼 得分:0
直接read出来呀!
将数据放入控件
发表于:2007-03-27 16:39:053楼 得分:0
http://cn.codeof.com/articles/.net/xml-applications/200.htm
发表于:2007-03-27 16:42:014楼 得分:0
dim   dt   as   new   datatable

dt.readxml(xmlpatch)
发表于:2007-03-27 16:42:045楼 得分:20
'注释:   load   saved   values   from   xml.  
private   sub   loadvalues(filepath)  
dim   xml_document   as   domdocument  
dim   values_node   as   ixmldomnode  

'注释:   load   the   document.  
set   xml_document   =   new   domdocument  
'xml_document.load   m_apppath   &   "values.xml "  
xml_document.load   filepath  

'注释:   if   the   file   doesn注释:t   exist,   then  
'注释:   xml_document.documentelement   is   nothing.  
if   xml_document.documentelement   is   nothing   then  
'注释:   the   file   doesn注释:t   exist.   do   nothing.  
exit   sub  
end   if  

'注释:   find   the   values   section.  
set   values_node   =   xml_document.selectsinglenode( "police ")  

'注释:   read   the   saved   values.  
txtfirstname.text   =   getnodevalue(values_node,   "groupid ",   "??? ")  
txtlastname.text   =   getnodevalue(values_node,   "sn ",   "??? ")  
txtstreet.text   =   getnodevalue(values_node,   "name ",   "??? ")  
txtcity.text   =   getnodevalue(values_node,   "reason ",   "??? ")  
txtstate.text   =   getnodevalue(values_node,   "comment ",   "没有 ")  
'txtzip.text   =   getnodevalue(values_node,   "reason ",   "??? ")  
end   sub  

private   sub   populatetreecontrol(   _             byval   document   as   system.xml.xmlnode,   _             byval   nodes   as   _               system.windows.forms.treenodecollection)                  
dim   node   as   system.xml.xmlnode            
for   each   node   in   document.childnodes                  
'   if   the   element   has   a   value,   display   it;                    
'   otherwise   display   the   first   attribute                    
'   (if   there   is   one)   or   the   element   name                    
'   (if   there   isn 't)                  
dim   [text]   as   string                  
if   node.value   <>   nothing   then                        
[text]   =   node.value                  
else                        
if   not   node.attributes   is   nothing   and   node.attributes.count   >   0   then                              
[text]   =   node.attributes(0).value                        
else                              
[text]   =   node.name                        
end   if                  
end   if                        
dim   new_child   as   new   treenode([text])                   nodes.add(new_child)                   populatetreecontrol(node,   new_child.nodes)            
next   node      
end   sub

发表于:2007-03-27 16:43:286楼 得分:0
xml   不会
up
发表于:2007-03-27 16:59:107楼 得分:0
多谢了


快速检索

最新资讯
热门点击