Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I currently have all the searching done for my needs. these functions and procedures will be used to manage XML based settings files. I need help changing the information.

C#
public String GetSetting(String Name, String File_Name)
        {
            string Temp = "";
            if (File.Exists(File_Name))
            {
                string sName = "";
                XmlTextReader reader = new XmlTextReader(File_Name);
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            sName = reader.Name;
                            break;
                        case XmlNodeType.Text:
                            if (sName == Name)
                            {
                                Temp = reader.Value;
                            }
                            break;
                    }
                }
                reader.Close();
            }
            else
            {
                //Error(File_Name + " was not found");
            }
            return Temp;
        }

When i call it i use a format like this
C#
Zeron.XML zXML = new Zeron.XML();
zXML.GetSetting("ServerRoot",sFile);


I want to be able to set a specific elements text trough a function or procedure and as i set it it will check if the element exists if it does exist the existing elements value will be changed.

I have been trying to do this but run into issues if any one could help it would be appreciated
Posted
Comments
midnight_ 12-Feb-14 1:55am    
Maybe you want to describe your "issues"
Per Söderlund 12-Feb-14 3:27am    
If its a small settings file it might be easier to serialize a class into an xml file.
Then just change value in class and overwrite xml file with a new one.
deserialize when you want to get class from xml file.

With this you dont have to spend time writing code for logic since the XmlSerializer takes care of everything.
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer(v=vs.110).aspx

I´m writing this as a comment because it´s not helping your code and its not solving your problem. I´m just suggesting an easier path that has been tested before.
Yuki24 12-Feb-14 11:06am    
I appreciate the suggestion but im creating this under my own library to make a custom settings file handler using xml files

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900