PDA

View Full Version : Xml view oddities



ekramer11
07-13-2006, 07:01 PM
I have successfully gotten my Xml editing actions to work. However, the final file appears to be changed in an way I didnt' specify when I was setting things up. I am dealing with .Net 2.0/ VS 2005. I am trying to write a connection string to the XML file based on user input.

My starting xml file looks like this...
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<clear/>
<add name="ConnectionString" connectionString="<<connstring>>" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>

This configuration works just fine with my app ( the actual connection string is removed of course ). What I am ending up with, after the XML View does it's editing is the following:

<?xml version="1.0" encoding="UTF-16"?>
<configuration>
<connectionStrings>
<clear></clear>
<add name="ConnectionString" connectionString="<<conn string>>" providerName="System.Data.SqlClient"></add>
</connectionStrings>
</configuration>


As far as I can tell, this is perfectly formed XML. However the added close tags for </clear> and </add> cause the ConfigurationManager object to not be able to find the specified connection string which causes the app to choke. If I remove them, and move the /> back to end end just like the original it works just peachy.

The only other difference I'm noting is the difference between UTF=16 and utf=8 in the header. But changing that doesn't make a difference.

Anyone have any idea what's going on with this?

ekramer11
07-14-2006, 10:19 AM
clear Element for connectionStrings (http://msdn2.microsoft.com/en-us/library/ayb15wz8.aspx)

One of our guys that is more familiar with XML than I am says that what appears to be happening is that the Xml View is violating the DotNetConfig.xsd schema by putting a </clear> tag after <clear>. It's well formed XML but apparently MS is expecting it to only be <clear/>. The link above notates this.

Apparently you can fix this problem simply by removing the <clear> tag from your original App.Config or by removing the node that Import Xml file creates for it during import so that it isn't touched.

Christopher Painter
07-11-2007, 11:49 PM
Bump... this was recently reported in another thread and Microsoft is looking into it.