EDN Admin
Well-known member
I need merge a section of type NameValueSectionHandler from two .config files (Main.config and Secundary.config in sample).
<br/>
The Main.config has another sections like appsetings and others.
<br/>
<br/>
Main.config:
<br/>
<div style="color:Black; background-color:White
<pre><span style="color:Blue <?
<span style="color:#a31515 xml
<span style="color:Red version
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue 1.0
<span style="color:Black "
<span style="color:Red encoding
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue utf-8
<span style="color:Black "
<span style="color:Blue ?>
<span style="color:Blue <
<span style="color:#a31515 configuration
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 section
<span style="color:Red name
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas
<span style="color:Black "
<span style="color:Red type
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue System.Configuration.NameValueSectionHandler
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule1
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule1,ParserSQL.Rule1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule2
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule2,ParserSQL.Rule2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Green <!-- other sections here -->
<span style="color:Blue </
<span style="color:#a31515 configuration
<span style="color:Blue >
[/code]
<br/>
<br/>
<br/>
Secundary.config:
<br/>
<div style="color:Black; background-color:White
<pre><span style="color:Blue <?
<span style="color:#a31515 xml
<span style="color:Red version
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue 1.0
<span style="color:Black "
<span style="color:Red encoding
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue utf-8
<span style="color:Black "
<span style="color:Blue ?>
<span style="color:Blue <
<span style="color:#a31515 configuration
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 section
<span style="color:Red name
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas
<span style="color:Black "
<span style="color:Red type
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue System.Configuration.NameValueSectionHandler
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule1
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule1,ParserSQL.Rule1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule3
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule3,ParserSQL.Rule3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule4
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule4,ParserSQL.Rule4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Blue </
<span style="color:#a31515 configuration
<span style="color:Blue >
[/code]
<br/>
<br/>
After merge process, the final config (Main.config modified)
<br/>
Main.config modified
<br/>
<br/>
<div style="color:Black; background-color:White
<pre> <span style="color:Blue <?
<span style="color:#a31515 xml
<span style="color:Red version
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue 1.0
<span style="color:Black "
<span style="color:Red encoding
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue utf-8
<span style="color:Black "
<span style="color:Blue ?>
<span style="color:Blue <
<span style="color:#a31515 configuration
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 section
<span style="color:Red name
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas
<span style="color:Black "
<span style="color:Red type
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue System.Configuration.NameValueSectionHandler
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule1
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule1,ParserSQL.Rule1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule2
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule2,ParserSQL.Rule2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule3
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule3,ParserSQL.Rule3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule4
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule4,ParserSQL.Rule4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Green <!-- other sections here -->
<span style="color:Blue </
<span style="color:#a31515 configuration
<span style="color:Blue >
[/code]
<br/>
<br/>
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px; border-collapse:collapse; line-height:18px Any suggestions or sample code in C# for best easy way using Xml.Linq (XDocument class) ?
<br/>
thanks in advanced
<br/>
View the full article
<br/>
The Main.config has another sections like appsetings and others.
<br/>
<br/>
Main.config:
<br/>
<div style="color:Black; background-color:White
<pre><span style="color:Blue <?
<span style="color:#a31515 xml
<span style="color:Red version
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue 1.0
<span style="color:Black "
<span style="color:Red encoding
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue utf-8
<span style="color:Black "
<span style="color:Blue ?>
<span style="color:Blue <
<span style="color:#a31515 configuration
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 section
<span style="color:Red name
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas
<span style="color:Black "
<span style="color:Red type
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue System.Configuration.NameValueSectionHandler
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule1
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule1,ParserSQL.Rule1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule2
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule2,ParserSQL.Rule2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Green <!-- other sections here -->
<span style="color:Blue </
<span style="color:#a31515 configuration
<span style="color:Blue >
[/code]
<br/>
<br/>
<br/>
Secundary.config:
<br/>
<div style="color:Black; background-color:White
<pre><span style="color:Blue <?
<span style="color:#a31515 xml
<span style="color:Red version
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue 1.0
<span style="color:Black "
<span style="color:Red encoding
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue utf-8
<span style="color:Black "
<span style="color:Blue ?>
<span style="color:Blue <
<span style="color:#a31515 configuration
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 section
<span style="color:Red name
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas
<span style="color:Black "
<span style="color:Red type
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue System.Configuration.NameValueSectionHandler
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule1
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule1,ParserSQL.Rule1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule3
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule3,ParserSQL.Rule3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule4
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule4,ParserSQL.Rule4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Blue </
<span style="color:#a31515 configuration
<span style="color:Blue >
[/code]
<br/>
<br/>
After merge process, the final config (Main.config modified)
<br/>
Main.config modified
<br/>
<br/>
<div style="color:Black; background-color:White
<pre> <span style="color:Blue <?
<span style="color:#a31515 xml
<span style="color:Red version
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue 1.0
<span style="color:Black "
<span style="color:Red encoding
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue utf-8
<span style="color:Black "
<span style="color:Blue ?>
<span style="color:Blue <
<span style="color:#a31515 configuration
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 section
<span style="color:Red name
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas
<span style="color:Black "
<span style="color:Red type
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue System.Configuration.NameValueSectionHandler
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 configSections
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule1
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule1,ParserSQL.Rule1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule2
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule2,ParserSQL.Rule2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule3
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule3,ParserSQL.Rule3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue <
<span style="color:#a31515 add
<span style="color:Red key
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue Rule4
<span style="color:Black "
<span style="color:Red value
<span style="color:Blue =
<span style="color:Black "
<span style="color:Blue ParserSQL.Reglas.Rule4,ParserSQL.Rule4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9744
<span style="color:Black "
<span style="color:Blue />
<span style="color:Blue </
<span style="color:#a31515 ParserSQL.Reglas
<span style="color:Blue >
<span style="color:Green <!-- other sections here -->
<span style="color:Blue </
<span style="color:#a31515 configuration
<span style="color:Blue >
[/code]
<br/>
<br/>
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px; border-collapse:collapse; line-height:18px Any suggestions or sample code in C# for best easy way using Xml.Linq (XDocument class) ?
<br/>
thanks in advanced
<br/>
View the full article