I have a XML File like that
<?xml version='1.0' encoding='utf-8' ?> <Configurations> <EmailConfiguration> <userName>xxxx</userName> <password>xxx</password> <displayName>xxxxx</displayName> <hostAddress>xxxx</hostAddress> <sslEnable>xxx</sslEnable> <port>xxx</port> </EmailConfiguration> <LogConfiguration> <logEnable>true</logEnable> <generalEnable>true</generalEnable> <warningEnable>true</warningEnable> <errorEnable>true</errorEnable> </LogConfiguration> </Configurations>
and I am using it as config file for my code and I want to retrieve their values (innerText) like that
bool logEnable = value comes from XML (logEnable) bool warningEnable = value comes from XML (warningEnable) bool errorEnable = value comes from XML (errorEnable) bool generalEnable = value comes from XML (generalEnable)
So how can I read their values to assign them to the boolean variables and if I wanted to change one of their values with false, How would I be able to do that ?
Thanks…
Regards…
P.s : If you wrote more explanatory codes, It would be so much appreciated.
Thanks again…
I left some work for you to complete 😉 Also, I didn’t write this is Visual Studio, and I didn’t compile it before hand. This code is provided as is with no guarantee or warranty. 😉
This is basic XML Read/Write process in .NET, though there are many options. You could use XPath queries, or if you are using .NET 3.5 you could use Linq to Sql which will give you street cred with the cool kids. But the above sample should get you up and running quickly, just promise you’ll go do some research on these other things too, you’ll be all the better for it.