all groups > dotnet xml > june 2005 >
You're in the

dotnet xml

group:

Create a .net 2.0 settings file problem


Re: Create a .net 2.0 settings file problem Martin Honnen
6/29/2005 12:00:00 AM
dotnet xml:


[quoted text, click to view]

You need to write out the element in the proper namespace e.g.
wr.WriteStartElement("SettingsFile",
"http://schemas.microsoft.com/VisualStudio/2004/01/settings")

--

Martin Honnen --- MVP XML
Create a .net 2.0 settings file problem Danny Springer
6/29/2005 7:44:04 AM
I am trying to create the following xml file with VS 2005:

<?xml version='1.0' encoding='utf-8'?>
<SettingsFile
xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings"
CurrentProfile="(Default)" GeneratedClassNamespace=""
GeneratedClassName="Extra">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings>
<Setting Name="Birth" Type="System.DateTime" Scope="Application">
<Value Profile="(Default)">15-09-1959</Value>
</Setting>
<Setting Name="SpecialColor" Type="System.Drawing.Color"
Scope="Application">
<Value Profile="(Default)">255; 192; 128</Value>
</Setting>
</Settings>
</SettingsFile>

I use the following code:

Dim Settings As New XmlWriterSettings

Settings.Indent = True
Settings.NewLineOnAttributes = True

Dim wr As XmlWriter = XmlWriter.Create("output.settings", Settings)

wr.WriteStartElement("SettingsFile")
' ****** This is the problem-line ******
wr.WriteAttributeString("xmlns",
"http://schemas.microsoft.com/VisualStudio/2004/01/settings")
wr.WriteAttributeString("CurrentProfile", "(Default)")
wr.WriteAttributeString("GeneratedClassNamespace", "")
wr.WriteAttributeString("GeneratedClassName", "Instellingen")

wr.WriteStartElement("Profiles")

etc. etc.

The line that starts to write the attribute xmlns is giving me problems. It
generates an exception:
The prefix '' cannot be redefined from '' to
'http://schemas.microsoft.com/VisualStudio/2004/01/settings' within the same
start element tag.

Re: Create a .net 2.0 settings file problem Danny Springer
6/29/2005 11:50:12 PM
[quoted text, click to view]
Ah, that's the way to do this. I'm very new in XML, now I understand.
Thank you.

AddThis Social Bookmark Button