Intellisense for custom config section problem with namespaces
I have just rolled a custom configuration section, created an accompanying schema document for Intellisense and added it to the Web.config's Schemas property as per Michael Stum's answer to another similar question.
Unfortunately, and possibly due to me creating the XSD by hand with limited knowledge, the Intellisense relies on an xmlns
attribute pointing to my XSD file's namespace being present in the custom config element. However, when running the project I get an Unrecognized attribute 'xmlns'. Note that attribute names are case-sensitive error.
I could probably just modify my XSD file to define the xmlns
attribute for that element, however I am wondering if this is just a bandaid fix to a larger problem. I must confess I don't have a very good understanding of XML namespaces so this might be an oppportunity to set me straight on a few things.
Here is the attributes for my XSD file's root xs:schema
element:
<xs:schema id="awesomeConfig"
targetNamespace="http://awesome.com/schemas"
xmlns="http://awesome.com/schemas"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
...
</xs:schema>
And on creating the element in the Web.config file, Visual Studio 2008 automatically appends:
<awesomeConfig xmlns="http://awesome.com/schemas"></awesomeConfig>
So have I misunderstood the meaning of the xs:schema
attributes at all, or is the proper solution as simple as it seems?
Your schema will need to omit the targetNamespace
attribute. In effect, this will put the schema contents into the default namespace.
That's necessary because the .NET configuration system has never permitted elements to be in a namespace.
精彩评论