1

私の web.config は次のようになります。

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

私の app.config (Exampleapp.config) は次のようになります。

<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>

「XML ドキュメントに複数のルート レベル要素を含めることはできません。」というエラーが表示されます。これを解決するにはどうすればよいですか?

4

2 に答える 2

0

この投稿によると、XML ドキュメントにはルート要素が 1 つしかなく、現在は 2 つあるため、このエラーが発生します。次のようなものを試してください:

<?xml version="1.0" encoding="utf-8"?>
<config>
     *Your code goes here*
</config>
于 2013-08-26T10:44:53.123 に答える
0

エラーが明確に示しているように、XML ファイルに必要なルート要素は 1 つだけです。次のように、2 つの親要素を 1 つの親要素に入れます。

<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>

それはうまくいくはずです。

于 2013-08-26T10:45:22.303 に答える