Reputation: 704
I have custom System.Configuration.ConfigurationSection
derived class which represents configuration section in my app.config
file. I also have xsd
schema document for that XML document. Configuration file has the following (simplified) structure:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="sectionOne" type="/*...*/" />
<section name="sectionTwo" type="/*...*/" />
<section name="sectionThree" type="/*...*/" />
</configSections>
<sectionOne xmlns="http://tempuri.org/MySchema.xsd">
<Container>
/*...*/
</Container>
</sectionOne >
<sectionTwo xmlns="http://tempuri.org/MySchema.xsd">
<Container>
/*...*/
</Container>
</sectionTwo >
<sectionThree xmlns="http://tempuri.org/MySchema.xsd">
<Container>
/*...*/
</Container>
</sectionThree >
</configuration>
As we can see, I have a several sections of that type, for various purposes, and I retrieve configuration data using ConfigurationManager
class:
ConfigurationManager.GetSection(sectionName);
Because section name is not constant string value, xsd
schema validate only elements that are children of the root element (starting from Container
tag). Therefore in VS2012, in Error list toolbar, I get a following messages:
Could not find schema information for the element 'http://tempuri.org/MySchema.xsd:SectionOne'.
Could not find schema information for the element 'http://tempuri.org/MySchema.xsd:SectionTwo'.
Could not find schema information for the element 'http://tempuri.org/MySchema.xsd:SectionThree'.
How to fix that validation mechanism.
Upvotes: 0
Views: 324
Reputation: 11973
There is no solution that does not involve changing a XSD: it is not possible to write a schema matching elements with arbitrary names. All the possible valid element names must be specified explicitly, so to validate correctly the names of the section elements must be added either to the http://tempuri.org/MySchema.xsd
schema or to DotNetConfig.xsd
.
Upvotes: 1