aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.GenericConfig/Xml/XmlConfig.cs
diff options
context:
space:
mode:
authorMW2007-04-02 12:56:35 +0000
committerMW2007-04-02 12:56:35 +0000
commit23ecc07caa19dce34bf56c6c3fac3e54cd2cdcff (patch)
treeace7dfc8b928c07ddb1f73b5a7b2c6de8a36687e /OpenSim.GenericConfig/Xml/XmlConfig.cs
parentminor bug (diff)
downloadopensim-SC_OLD-23ecc07caa19dce34bf56c6c3fac3e54cd2cdcff.zip
opensim-SC_OLD-23ecc07caa19dce34bf56c6c3fac3e54cd2cdcff.tar.gz
opensim-SC_OLD-23ecc07caa19dce34bf56c6c3fac3e54cd2cdcff.tar.bz2
opensim-SC_OLD-23ecc07caa19dce34bf56c6c3fac3e54cd2cdcff.tar.xz
Added OpenSim.GenericConfig.Xml project, so we can swap to a more generic configuration method, so that it is easier to load configuration data from a ogs server
Diffstat (limited to '')
-rw-r--r--OpenSim.GenericConfig/Xml/XmlConfig.cs92
1 files changed, 92 insertions, 0 deletions
diff --git a/OpenSim.GenericConfig/Xml/XmlConfig.cs b/OpenSim.GenericConfig/Xml/XmlConfig.cs
new file mode 100644
index 0000000..39321cc
--- /dev/null
+++ b/OpenSim.GenericConfig/Xml/XmlConfig.cs
@@ -0,0 +1,92 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Xml;
5using OpenSim.Framework.Interfaces;
6
7namespace OpenSim.GenericConfig
8{
9 public class XmlConfig : IGenericConfig
10 {
11 private XmlDocument doc;
12 private XmlNode rootNode;
13 private XmlNode configNode;
14 private string fileName;
15
16 public XmlConfig(string filename)
17 {
18 fileName = filename;
19 }
20
21 public void LoadData()
22 {
23 doc = new XmlDocument();
24 try
25 {
26 XmlTextReader reader = new XmlTextReader(fileName);
27 reader.WhitespaceHandling = WhitespaceHandling.None;
28 doc.Load(reader);
29 reader.Close();
30 }
31 catch (Exception e)
32 {
33 Console.WriteLine(e.Message);
34 return;
35 }
36 try
37 {
38 rootNode = doc.FirstChild;
39 if (rootNode.Name != "Root")
40 throw new Exception("Error: Invalid .xml File. Missing <Root>");
41
42 configNode = rootNode.FirstChild;
43 if (configNode.Name != "Config")
44 throw new Exception("Error: Invalid .xml File. <Root> first child should be <Config>");
45
46 }
47 catch (Exception e)
48 {
49 Console.WriteLine(e.Message);
50 }
51 }
52
53 public string GetAttribute(string attributeName)
54 {
55 string result = "";
56 if (configNode.Attributes[attributeName] != null)
57 {
58 result = ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value;
59 }
60 return result;
61 }
62
63 public bool SetAttribute(string attributeName, string attributeValue)
64 {
65 if (configNode.Attributes[attributeName] != null)
66 {
67 configNode.Attributes.GetNamedItem(attributeName).Value = attributeValue;
68 }
69 else
70 {
71 XmlAttribute attri;
72 attri = doc.CreateAttribute(attributeName);
73 attri.Value = attributeValue;
74 configNode.Attributes.Append(attri);
75 }
76 return true;
77 }
78
79 public void Commit()
80 {
81 doc.Save(fileName);
82 }
83
84 public void Close()
85 {
86 configNode = null;
87 rootNode = null;
88 doc = null;
89 }
90
91 }
92}