2010-09-26 53 views
1

ConfigurationElementCollection对象是否可以为其元素包含另一个ConfigurationElementCollection对象?ConfigurationElementCollection对象是否可以为其元素包含另一个ConfigurationElementCollection对象?

我有这样的XML其中testsection是部分根:

<testsection> 
    <head> 
     <metaData> 
      <metaGroup id="general"> 
       <meta name="Content-type" content="text/html; charset=utf-8" type="http-equiv" /> 
      </metaGroup> 
      <metaGroup id="default"> 
       <meta name="something" content="test" type="name" /> 
      </metaGroup> 
     </metaData> 
    </head> 
</testsection> 

是否有可能与配置节,和的ConfigurationElement ConfigurationElementCollection中,可以读出上面的XML创建类?

问题是,当我们实现ConfigurationElementCollection时,我们无法在collection中定义该元素是另一个ConfigurationElementCollection类型。

我可以让它工作,如果配置部分是这样的(没有元组元素):

<testsection> 
     <head> 
      <metaData> 
        <meta name="Content-type" content="text/html; charset=utf-8" type="http-equiv" /> 
        <meta name="something" content="test" type="name" /> 
      </metaData> 
     </head> 
    </testsection> 

回答

1

我认为只有的ConfigurationElement对象可以包含ConfigurationElementCollection中的对象(ConfigurationElementCollection中必须有其父的ConfigurationElement)。所以我认为如果metaGroup是ConfigurationElement并且如果我添加一个新的ConfigurationElementCollection(metaGroupCollection)作为元ConfigurationElement的父级,我可以解决这个问题。

<testsection> 
     <head> 
      <metaData> 
       <metaGroup id="general"> 
        <metaGroupCollection> 
         <meta name="Content-type" content="text/html; charset=utf-8" type="http-equiv" /> 
        </metaGroupCollection> 
       </metaGroup> 
       <metaGroup id="default"> 
        <metaGroupCollection> 
         <meta name="something" content="test" type="name" /> 
        </metaGroupCollection> 
       </metaGroup> 
      </metaData> 
     </head> 
    </testsection> 
相关问题