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



一百分的问题,如何历遍自定义配置节(组),一百分的问题。


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


一百分的问题,如何历遍自定义配置节(组),一百分的问题。[已结贴,结贴人:kissmmmi]
发表于:2007-08-11 00:19:35 楼主
http://community.csdn.net/expert/topic/5703/5703370.xml?temp=.6602899

晚上,上csdn看到的帖子,虽然已经帖了。但是,我发现它实现真正的历遍自

定义配置节,如何历遍呢,想到现在也没有弄出来,特向大家请教。


为了大家看方便,复制如下

是web.config中的

<?xml   version= "1.0 "   encoding= "utf-8 "?>

<configuration>
    <configsections>
        <sectiongroup   name= "f1 ">
            <section   name= "f2 "   type= "student.test,student "/>
        </sectiongroup>
    </configsections>
    <f1>
        <f2>
            <f3   name= "email "   texttype= "a++ "   info= "important "   message= "{0}   非常重要的 "/>
            <f3   name= "email1 "   texttype= "a "   info= "level1 "   message= "{0}一般! "/>
        <f3   name= "email2 "   texttype= "a+ "   info= "level2 "   message= "{0}平常{1}! "/>
                    </f2>
    </f1>
        <appsettings/>
        <connectionstrings/>
   
        <system.web>
         
                <compilation   debug= "true "   />
           

                <customerrors   mode= "remoteonly "   defaultredirect= "genericerrorpage.htm ">
                        <error   statuscode= "403 "   redirect= "noaccess.htm "   />
                        <error   statuscode= "404 "   redirect= "filenotfound.htm "   />
                </customerrors>
                -->
        </system.web>
</configuration>


就是要历遍f2下的所有f3。
发表于:2007-08-11 00:25:541楼 得分:0
e.g
xmlnode   xn=xmldoc.selectsinglenode( "bookstore ");  

xmlnodelist   xnl=xn.childnodes;  

foreach(xmlnode   xnf   in   xnl)  
{  
xmlelement   xe=(xmlelement)xnf
console.writeline(xe.getattribute( "genre "));//显示属性值  
console.writeline(xe.getattribute( "isbn "));  

xmlnodelist   xnf1=xe.childnodes;  
foreach(xmlnode   xn2   in   xnf1)  
{  
console.writeline(xn2.innertext);//显示子节点点文本  
}  
}  
发表于:2007-08-11 00:35:592楼 得分:0
学习哈
发表于:2007-08-11 00:39:213楼 得分:0
就当它是一个普通的xml文件
自己去遍历,拿到那些值
发表于:2007-08-11 00:42:114楼 得分:0
你们小瞧了我的问题,用历遍xml的方法,谁不会啊,要用vs2005针对自定义配置节的方法来作,才行的。
发表于:2007-08-11 00:46:235楼 得分:0
2.0提供了这个system.configuration.configurationmanager.getsection()

但是,没有办法历遍。
发表于:2007-08-11 00:55:396楼 得分:0
最后up一下。
发表于:2007-08-11 00:59:447楼 得分:0
mark
发表于:2007-08-11 01:04:188楼 得分:0
configurationmanager.getsection用过,不过没有历遍
发表于:2007-08-11 12:39:369楼 得分:0
怎么没人回呢???up
发表于:2007-08-11 12:39:5510楼 得分:0
up
发表于:2007-08-11 12:40:1911楼 得分:0
up,up,up
发表于:2007-08-11 13:12:1112楼 得分:0
lz,你都能读出来了,历遍还不会???

上面的那方法返回一个哈希表,历遍那个表就行了。
发表于:2007-08-11 14:29:2113楼 得分:0
2.0提供了这个system.configuration.configurationmanager.getsection()

但是,没有办法历遍。

==========

getsection   返回   <section   type= "... "   />   指定的自定义配置节处理信息,
你要对齐进行类型强制转换,

是否提供遍历方式,以及如何遍历,那完全是你的自己事情,

比如,这里对于   f2   就是   student.test   类的事情了
发表于:2007-08-11 15:18:2914楼 得分:0

把它看成一个普通的xml文件
用xmldocument,xmlnode   即可轻易的遍历
发表于:2007-08-11 16:42:2715楼 得分:0
这里对于   f2   就是   student.test   类的事情了????


什么意思???
发表于:2007-08-11 16:50:2816楼 得分:0
你不是指定了   student.test   是   f2   的处理类迈?

自然是在这个类里面实现了,通常是公开一个   configurationpropertycollection   类型   properties

是否认真阅读   msdn   中关于自定义配置节处理程序的文章?

自定义配置节,应该扩展类     configurationsection,   此基类已经定义了   properties   属性

发表于:2007-08-11 16:56:4917楼 得分:0
我看msdn了,我都晕了。

开始时,还明白,处理程序都继承自configurationsection类。可当,是配置节组是,就不明白了。

再说到您说的,怎么配置节又变成类呢??
发表于:2007-08-11 16:58:4918楼 得分:0
我也没有调用配置节处理程序啊??
发表于:2007-08-11 16:59:0419楼 得分:0
student.test   testsection   =   (student.test)system.configuration.configurationmanager.getsection(
                        "f1/f2 ");
发表于:2007-08-11 16:59:4320楼 得分:0
用xpath来表示的话
"//f2/f3 "
发表于:2007-08-11 17:03:0721楼 得分:0
to   jinglecat(晓风残月   > >   问题需简洁,错误要详细)


配置节处理程序中不是不,对第一个节点都要操作并返回一个值呢??
发表于:2007-08-11 17:04:5722楼 得分:0
网上的文章,虽然是sectiongroup,但都只是含有一个
如:
  <f1>
        <f2>
            <f3   name= "email "   texttype= "a++ "   info= "important "   message= "{0}   非常重要的 "/>
        </f2>
    </f1>

当再我一个f3时,就出错,说f3只能出现一次,我都晕了,不是组吗??
发表于:2007-08-11 17:05:4423楼 得分:0
学习,帮顶一下
发表于:2007-08-11 17:13:0924楼 得分:0
你可以看看   web.config   中的   customerrors   配置节是如何处理的,刚好与你的目标配置类似
发表于:2007-08-11 17:13:4725楼 得分:0
用   reflector   反汇编   system.web.dll   找到   customerrorssection   类
发表于:2007-08-11 17:16:0626楼 得分:0
如上面我的代码:

  public   class tes   :   configurationsection



发表于:2007-08-11 17:26:3927楼 得分:0
http://hi.baidu.com/ay168/blog/item/24434022b03190a54623e8b7.html

这是一个  asp.net   使用   configurationsection   创建自定义配置节 的文章。

它就用了jinglecat(晓风残月   > >   问题需简洁,错误要详细)   说的。
但是有一个问题,即然,配置节处理程序是用于处理指定结点的数据,那么不是要给指定的节点下的所有节都定一个属性呢??


可能您没有听明白,我上说的话(我都语无论次了),那么就请在上面我给的文章中,的

  <mycustomgroup>
            <mycustomsection   myattrib1= "clowns ">
                <mychildsection  
                        mychildattrib1= "zippy "  
                        mychildattrib2= "michael   zawondy   "/>
<!--此处再加一个mychildsection   ,就会出错,不明白为什么-->
            </mycustomsection>
        </mycustomgroup>

发表于:2007-08-11 17:34:0228楼 得分:0
这个文章的代码好像是   msdn   里面的原原本本的   demo


<!--此处再加一个mychildsection   ,就会出错,不明白为什么-->

=======

那么这个得定义个继承自   configurationelementcollection   的集合

并定义一个继承自   configurationelement   节点元素
发表于:2007-08-11 17:38:5729楼 得分:0
<mycustomgroup>
            <mycustomsection   myattrib1= "clowns ">
                <mychildsection  
                        mychildattrib1= "zippy "  
                        mychildattrib2= "michael   zawondy   "/>
            <mychildsection  
                        mychildattrib1= "two "  
                        mychildattrib2= "two   three "/>
            </mycustomsection>
        </mycustomgroup>

这样定义,本来是不应该错的,可是现在不行了
发表于:2007-08-11 17:49:5130楼 得分:100
发到   xfwang0724@gmail.com   ,晚上给你一个   demo
发表于:2007-08-11 17:52:0331楼 得分:0
jinglecat(晓风残月   > >   问题需简洁,错误要详细)  

谢谢了,我一会就发信。谢谢了。我也在努力呢。
发表于:2007-08-11 17:56:1232楼 得分:0
jinglecat大哥,我已经发完了。麻烦了,我也正在找原因。
发表于:2007-08-11 18:37:4533楼 得分:0
大哥,能不能也给我一个demo啊!接分
发表于:2007-08-11 19:30:0034楼 得分:0
up
发表于:2007-08-11 22:27:3535楼 得分:0
我已经收到晓风大哥的演示代码了,不知道那们兄弟收到没有,如果没有给我发信息。

真是“南慕白(兄),北晓峰(兄)”,再次谢谢您了,能得到您的帮助,真是有幸。

没有什么说的,结贴了。希望好心人一切顺利。
发表于:2007-08-13 16:50:3436楼 得分:0
学习中。。
发表于:2007-08-14 08:58:5037楼 得分:0
向楼主索demo   ylhyh#yahoo.com.cn   顺便mark
发表于:2007-08-14 15:36:0138楼 得分:0
学习
发表于:2007-10-20 00:29:0239楼 得分:0
贡献demo出来学习一下也好啊


快速检索

最新资讯
热门点击