looking for a very basic XML read example

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
 
S

Stimp

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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top