Register  Login       Search  
Forum  
 
  
 
Forum  Forum     
 
SearchForum Home
  Mvp.Xml Project  XInclude.NET  Trying to split...
 Trying to split up config into multiple files
 
jm
3 posts
Joined
7/14/2006

Trying to split up config into multiple files
Posted: 14 Jul 06 2:22 PM (United States) Modified By jm  on 7/14/2006 2:22:47 PM)

I'm trying to split up my main App.config file into multiple files to make it easier for my support guys so the config file they open up every tag will be one that needs to be changed instead of having some that do not need to be changed in there.

The following code gets called when the structure is deserialized from the Xml, the parent and hmm are both null and configSection is the XmlNode . When xs.Deserialize gets called it ends up throwing the exception "There are multiple root elements. Line 2, position 2." I'm guessing that this is because in RarelyChanges.config there are multiple root elements.

Is there anyway to just have multiple lines of the second Xml document included in the App.config file when I do the xi:include? Sorry if this made little sense, its the end of the day and I'm just tired from trying to figure this out.



public object Create( object parent, object hmm, XmlNode configSection )
{
 object tmpObj = null;
 tmpObj = xs.Deserialize( new XIncludingReader( new StringReader( configSection.OuterXml ) ) );
 return tmpObj;
}


App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
  <section name="application" type="AppStructure"/>
  <section  name="applicationConfigurationManagement"
   type="Microsoft.ApplicationBlocks.ConfigurationManagement.ConfigurationManagerSectionHandler,Microsoft.ApplicationBlocks.ConfigurationManagement, Version=1.0.0.0,Culture=neutral,PublicKeyToken=c14a5885e5232caa" />
 </configSections>
 <application xmlns:xi="http://www.w3.org/2001/XInclude">
  <AppStructure xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
   <xi:include href="RarelyChanges.config" />
                                                <NumberOfDays>7</NumberOfDays>
  </AppStructure>
 </application>
 <applicationConfigurationManagement defaultSection="application" >
  <configSection name="application">
   <configCache enabled="false" refresh="1 * * * *" />
   <configProvider assembly="Microsoft.ApplicationBlocks.ConfigurationManagement,Version=1.0.0.0,Culture=neutral,PublicKeyToken=c14a5885e5232caa"
         type="Microsoft.ApplicationBlocks.ConfigurationManagement.Storage.XmlFileStorage"
         signed="false"
         refreshOnChange="true"
         encrypted="false" />
  </configSection>
 </applicationConfigurationManagement>
</configuration>

 


RarelyChanges.config

<NumberOfMonths>12</NumberOfMonths>
<NumberOfWeeks>52</NumberOfMonths>


I guess I would like the <AppStructure> part of the final version of App.config to "look" something like this

<AppStructure>
     <NumberOfMonths>12</NumberOfMonths> 
     <NumberOfWeeks>52</NumberOfMonths>
     <NumberOfDays>7</NumberOfDays>
</AppStructure>

jm
3 posts
Joined
7/14/2006

Re: Trying to split up config into multiple files
Posted: 19 Jul 06 9:03 AM (United States)

Well, I have still not been able to come up with a solution for splitting my config file into multiple files which will work with the XmlSerializer.Deserialize method. 

Stepping through the generated XmlSerializer code and watching it attempt to deserialize the xml is simply frustrating because it appears like it should be working (in watch window if statements are looking like they are true but get stepped over).  I did figure out how to have my external app config set up and the main app.config pointing towards it using the xpointer part of XInclude.

I think I'm just going to look into generating a temporary .config file now by combining external config files whenever I need to use the App.config file.  Probably not the best solution to this problem but since I'm at the point where it really seems like it should be working how it is set up and it isn't I'm at a lost of what to try next.

jm
3 posts
Joined
7/14/2006

Re: Trying to split up config into multiple files
Posted: 20 Jul 06 7:59 AM (United States)
I've come up with a solution that works.

This is what I'm doing right now:

XIncludingReader xir = new XIncludingReader(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
XmlDocument doc = new XmlDocument();
doc.Load(xir);
XmlNodeReader reader = new XmlNodeReader(doc);

Then I'm planning on moving to the correct Node in the reader and passing that into my XmlSerializer to deserialize it.
  Mvp.Xml Project  XInclude.NET  Trying to split...
Forum Home  Search