2012-10-10 63 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> 
相關問題