Re: XPath and Configuration
Don't use XPath. The Framework has an inbuilt mechanism for editing the config file. Follow the Protected Configuration link in my signature for an example.
Re: XPath and Configuration
Thanks for that but I dont think I can use that approach. That is if you are using the "System.Configuration;" namespace.
You see the config file is required by a reflected assembly which is why I would like to use XPath.
Re: XPath and Configuration
Actually I dont really need to use XPath.
All I need is to extract the value of the two nodes. I have tried to get data using
Code:
XmlNodeList elemList = doc.GetElementsByTagName("SupplierId");
but for the life of me it returns a count of 0.
What am I doing wrong ?
Re: XPath and Configuration
I don't see any SupplierId tag in that XML code. Note that within the appSettings section all the tags are named "add". If you were looking for that loggingLevel bit then you'd have to get a tag whose name was "add" and had an attribute named "key" with a value of "loggingLevel".
Re: XPath and Configuration
I didn't see anything about 2005, so perhaps some LINQ to XML?
vb.net Code:
Dim root As XElement = XElement.Load("c:\MyConfig.xml")
Dim connString = _
(From el In root.<connectionStrings>.<add> _
Select el.@connectionString).First()
MessageBox.Show(connString)
Re: XPath and Configuration
I'm a bit screwed here.
I use the following to open the doc:
Code:
Dim doc As New XmlDocument()
doc.Load("Myconfig.exe.config")
And I use this to get the tags with "add" in them :
Code:
Dim elemList As XmlNodeList = doc.GetElementsByTagName("add")
This returns the appropriate number of nodes.
Now how do I find the "<add key="loggingLevel" value="4" />" and how do I update the value ?
This is crazy. I'm reflecting assemblies but can't figure out simple XML:blush:
I'm an embaressment !!
Re: XPath and Configuration
The tag name is "add" and it has attributes named "key" and "value". You need to get the "add" tag with a "key" attribute whose value is "loggingLevel" and then set the value of its "value" attribute.