2012-10-10 66 views
1

收集要素我认为这将是一些简单的事,因为我有一个XML部分,如:应用程序/ Web配置自定义部分,带有属性

<InterfaceDetails> 
    <Interface name="TestInterface1"> 
     <Details data="xxxxxx" /> 
     <Details data="yyyyyy" /> 
    </Interface> 
    <Interface name="TestInterface2"> 
     <Details data="zzzzzz" /> 
    </Interface> 
</InterfaceDetails> 

的区段处理器配合起来不错,但它抛出一个错误读取XML说,它不能找到“name”属性,当现在没有把代码LOAD在这里我已经得到了目前在以下类:

  • InterfaceDetailsS​​ection

主要部分容器有一个名为Interface的属性,该属性链接到InterfaceElementCollection。

  • InterfaceElementCollection

这是元素集合派生类应该暴露的name属性和下面的细节元素。我曾尝试给这个类一个名为name的属性,这似乎工作,但后来我得到了有关子元素的另一个错误。

  • DetailsElement

这包含了详细元素内的数据属性。

我希望能够理想地拉出每个接口,然后为每个接口抽出细节,但是对于我的生活,甚至看着这个领域的过多教程,他们似乎都没有涵盖多个孩子中的多个孩子,或者如果他们没有集合上的属性。

任何人都可以看到任何明显的错误或给我任何指示,哪里即将出错。

+0

尝试,我发现这样一个问题:http://stackoverflow.com/questions/8829414/how-to-have-custom-attribute-in-configurationelementcollection这是非常有益的,与1个界面元素一起工作,但我似乎没有超过1个界面元素,或者它摔倒了,我希望这会是一些简单的事情,将在几分钟内回答:( – Grofit

回答

0

你可以用这个

<configuration> 

    <!-- Configuration section-handler declaration area. --> 
     <configSections> 
     <sectionGroup name="myCustomGroup"> 
      <section 
      name="myCustomSection" 
      type="MyConfigSectionHandler.MyHandler, MyCustomConfigurationHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" 
      allowLocation="true" 
      allowDefinition="Everywhere" 
      /> 
     </sectionGroup> 
      <!-- Other <section> and <sectionGroup> elements. --> 
     </configSections> 

     <!-- Configuration section settings area. --> 



<myCustomGroup> 
    <myCustomSection myAttrib1="Clowns"> 

    </myCustomSection> 
    </myCustomGroup> 


    </configuration> 
相关问题