开发者

Can ConfigurationElementCollection object contain for its elements another ConfigurationElementCollection objects?

开发者 https://www.devze.com 2023-01-17 11:40 出处:网络
Can ConfigurationElementCollection object contain for its elements another ConfigurationElementCollection objects?

Can ConfigurationElementCollection object contain for its elements another ConfigurationElementCollection objects?

I have this xml where testsection is section root:

<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>

Is it possible to create classes with ConfigurationSection, ConfigurationElement and ConfigurationElementCollection that can read above xml?

The problem is that when we are implementing ConfigurationElementCollection we can't define that element in collection is of type another ConfigurationElementCollection.

I can make it to work if configuration section is like this (without metaGroup elements):

<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>


I think that only ConfigurationElement objects can contain ConfigurationElementCollection objects (ConfigurationElementCollection must have for its parent ConfigurationElement). So I think that I can solve this problem if metaGroup would be ConfigurationElement and if I add a new ConfigurationElementCollection (metaGroupCollection) as parent of meta 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消