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>
是否可以使用可以读取上面 xml 的 ConfigurationSection、ConfigurationElement 和 ConfigurationElementCollection 创建类?
问题是,当我们实现 ConfigurationElementCollection 时,我们无法定义集合中的元素是另一个 ConfigurationElementCollection 类型。
如果配置部分是这样的(没有metaGroup元素),我可以让它工作:
<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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为只有 ConfigurationElement 对象可以包含 ConfigurationElementCollection 对象(ConfigurationElementCollection 必须具有其父 ConfigurationElement)。所以我认为如果 metaGroup 是 ConfigurationElement 并且添加一个新的 ConfigurationElementCollection (metaGroupCollection) 作为元 ConfigurationElement 的父级,我可以解决这个问题。
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.