0

I wanna ask about WPF C# and XML connections.

Let's skip that part, when I have to create an XML file. I already have one named "xmlconf.xml". And now I want to access it's values from C# code (without using XAML binding). They also have to be re-written during the runtime.

This is a part of my XML file

<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings"    CurrentProfile="(Default)" GeneratedClassNamespace="SampleApp" GeneratedClassName="xmlconf">
    <Profiles />
    <Settings>
        <Setting Name="string_a" Type="System.String" Scope="User">
            <Value Profile="(Default)">some_string_a</Value>
        </Setting>
    </Settings>
</SettingsFile>

If you think that you're able to help me but have some misunderstanding, please post comments, so I'll make changes to the post.

GeeMitchey
  • 134
  • 1
  • 3
  • 13
  • What does reading XML have to do with data binding? Where you read and write your config/data files is a design decision, how you do it is a matter of implementation - and there are various libraries available for working with XML. Personally I would read such data into a clear, descriptive data structure, in a single place, and I would expose that to a view via data-binding. That keeps view-related code simpler - it's only for displaying content, not processing it. And the data processing code can be used without forced to create a view. – Pieter Witvoet Jan 18 '15 at 22:00

2 Answers2

0

You can use XDocument to access XML data.

var doc = XDocument.Load("xmlconf.xml");

See How to get value of child node from XDocument or MSDN for more details.

Community
  • 1
  • 1
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
0

That looks a lot like a Visual Studio settings file...

Assuming your project is correctly configured with the settings file, you can just read/write to the values in it like so:

Properties.Settings.Default.string_a = "abc"
Scott
  • 533
  • 1
  • 3
  • 10