looking for a very basic XML read example

  • Thread starter Thread starter Stimp
  • Start date Start date
S

Stimp

Hi all,

I'm trying to read a particular node value from an XML file, but I've
done some searching on the net and there doesn't seem to be a very basic
example.

Basically here's what I want to do...

- In my web.config I have:

<configuration>
<appSettings>
<add key="constring" value="blah" />
</appSettings>

....

- I want to retrieve the value of the key "constring"


I'm performing this from a dll so I can't access this value using
ConfigurationSettings.AppSettings("constring")

(plus I want to learn how to read xml files)


I'm sure this is only about 4 lines of code, anyone got any samples of
how to do this?

Much thanks,
Peter
 
You want to do an XPath SelectSingleNode - you can do this from an
XmlDocument or an XPathNavigator from the XPathDocument (don't remember if
you can go direct).

Hi David,

So basically the code would be something like...


XmlDocument oDoc = new XmlDocument();

oDoc.Load("web.config");

sConnstring = oDoc.SelectSingleNode("//constring");

?

That's 3 lines.. so I'm close to my 4 line estimate :)
 
Back
Top