I have around twenty XML files in various Visual Studio 2008 projects, each of which both defines certain objects and refers to objects in the file and other files. e.g.
<some_object name="a" />
<some_object name="b"><refers_to ref="a" /></some_object>
Files refer to other files using custom <include file="blah.xml" />
elements, rather than using XInclude (which has no support in .Net) or !ENTITY (which doesn't allow the referred to files to be well-formed documents in their own right).
I have created a .xsd schema generator which looks through all the object definitions in the files and produces a .xsd schema file which can then be used to validate that all the object definitions refer to objects that exist. I then include that schema in all the files using xsi:noNamespaceSchemaLocation="generated.xsd"
.
I've set up the solution to generate the xsd from all the xml files when it compiles and copy the file into the folders containing the xml. The intention is that xsi:noNamespaceSchemaLocation="generated.xsd"
will now refer to that locally copied file and it should all validate nicely.
The problem I am having is that Visual Studio fails to apply the schema to the files so I get no intellisense during editing. It seems that Visual Studio keeps caching the xsd file every time it is copied. If I look at the Xml->Schemas... menu then generated.xsd appears multiple times, apparently unused. If I manually remove all references to the schema in that window, then Visual Studio seems to use the local file and starts working properly again.
I cannot merge all the files into one file which would permit the use of xsi:keyref
to validate the referential integrity, because it would be too large to work with effectively, and the primary goal of the schema is to have the intellisense and edit-time checking when working with the files in VS.
Does anyone have any ideas about how I can solve this problem?