1

My web.config looks like this:

<configuration>
  <configSections>
    <appSettings configSource="Exampleapp.config" />
    <connectionStrings configSource="ExampleProd.config" />
  </configSections>
<configuration>

My app.config (Exampleapp.config) looks like this:

<configSections>
  <sectionGroup name="exampleSettings">
    <section name="blah" type="System.Configuration.NameValueSectionHandler" />
    <section name="foo" type="System.Configuration.NameValueSectionHandler" />
  </sectionGroup>
</configSections>
<exampleSettings>
  <blah>
    <add key="me" value="1" />
  </blah>
  <foo>
    <add key="you" value="2" />
  </foo>
</exampleSettings>

I'm getting an error that says: XML document cannot contain multiple root level elements. How do I resolve this?

dotnetN00b
  • 5,021
  • 13
  • 62
  • 95

2 Answers2

0

According to this post, you get that error because the XML document must only have one root element and you currently have two. Try something like:

<?xml version="1.0" encoding="utf-8"?>
<config>
     *Your code goes here*
</config>
Community
  • 1
  • 1
m-oliv
  • 419
  • 11
  • 27
  • Whatever I put as the root element gives the error: The "x" element is not declared. – dotnetN00b Aug 26 '13 at 11:17
  • @dotnetN00b, take a look at the answer to [this post](http://stackoverflow.com/questions/7684398/the-packages-element-is-not-declared). – m-oliv Aug 26 '13 at 11:19
0

As error clearly specifies, You only need to have one root element in XML file. Put you two parent elements in one parent element like,

<rootEle>

<configSections>
  <sectionGroup name="exampleSettings">
     <section name="blah" type="System.Configuration.NameValueSectionHandler" />
     <section name="foo" type="System.Configuration.NameValueSectionHandler" />
  </sectionGroup>
</configSections>
<exampleSettings>
  <blah>
     <add key="me" value="1" />
  </blah>
  <foo>
     <add key="you" value="2" />
  </foo>
</exampleSettings>

</rootEle>

It should work.

hnDabhi
  • 75
  • 8