[C#] Read from XML file?

hyperb0le

New member
Joined
Feb 23, 2003
Messages
2
I have an XML file which reads:

<?xml version="1.0"?>
<Wallpaper>
<Name>Default</Name>
</Wallpaper>

Now i need to read this file from my c# application and assign the value of <Name> to a string.

This is for the preferences file of my app.

Thanks in advance.
 
One way to accomplish this is to load the XML file into an
XmlDocument class. Then you can easily access the XML DOM and
change elements and attributes, and execuce XPath statements.

Here, path is a string containing the file name and path of the
XML file:
C#:
using System.Xml; // This belongs at the top of your code file

XmlDocument doc = new XmlDocument();
string myValue;

doc.Load(path);

myValue = doc.ChildNodes["Name"].InnerText;

Sorry if there are any syntax errors in the code, since Ive only
just started working with C#. This snippet should give you the
general idea about how to go about what you want.

[edit]Fixed up the code a little[/edit]
 
Back
Top