クライアントの要求ごとに C# で XML ページをフォーマットしようとしています。以下は、現在XMLで作成しているものです
<?xml version="1.0" encoding="utf-8"?>
<!--This is to write the connection strings, text file location, and report destination.-->
<AdminPaths Name="sqlConnection1" connectionString="asdf">
<TextPath>
<Key Value="Test3" xmlns="Path" />
</TextPath>
</AdminPaths>
これは私がしたいことです:
<?xml version="1.0" encoding="utf-8"?>
<!--This is to write the connection string, text file location, and report destination.-->
<AdminPaths>
<Name="sqlConnection1" connectionString="asdf">
</AdminPaths>
<TextPath>
< Key="Path" Value="Test3">
< Key="Report" Value="Test2">
</TextPath>
現在使用しているコードは次のとおりです。
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter writer = XmlWriter.Create("C:\\Users\\fthompson11\\WebFile.xml", settings);
writer.WriteStartDocument();
writer.WriteComment("This is to write the connection strings, text file location, and report destination.");
writer.WriteStartElement("AdminPaths");
writer.WriteAttributeString("Name", "sqlConnection1");
writer.WriteAttributeString("connectionString", "asdf");
writer.WriteStartElement("TextPath");
writer.WriteStartElement("Key", "Path");
writer.WriteAttributeString("Value", "Test3");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
writer.WriteEndElement(); を使用してみました。writeAttributeString を開始した後、「XML フラグメントを書き込む場合は、ConformanceLevel 設定が ConformanceLevel.Fragment または ConformanceLevel.Auto に設定されていることを確認してください」というエラーが表示されます。それは私がやりたいことではないと思いますか?どんな助けでも大歓迎です。
ありがとう。