Read_XML_Apps_Class
1| using System;
2| using System.Collections.Generic;
3| using System.Linq;
4| using System.Text;
5|
6| //add references
7| using System.IO;
8| using System.Xml;
9|
10| namespace MyDesktop
11| {
12| class Read_XML_Apps_Class
13| {
14| string sApps_Parameter_File = "";
15|
16| //declare an array of objects
17| public Apps_Class[] oApp;
18|
19| //Declare objects in required classes to read an xml file
20| XmlDocument oDoc;
21| XmlNodeReader oNodeReader;
22|
23| //Area to store xml user node content
24| public string sXml_Path = "";
25| public string sXml_Description = "";
26| public string sXml_Start_in = "";
27| public string sXml_Parameter = "";
28|
29| //constructor method
30| public Read_XML_Apps_Class(string sApps_XML_File_Location)
31| {
32| //Set the location of this user's Apps XML file
33| sApps_Parameter_File = sApps_XML_File_Location;
34| }
35|
36| //does xml file exit?
37| public bool Parameter_File_Exist()
38| {
39| bool bExists = true;
40|
41| if (!File.Exists(sApps_Parameter_File))
42| {
43| bExists = false;
44| }
45| return bExists;
46| }
47|
48| //open the xml file and declare an array of user objects
49| public bool Open_XML_Parameter_File()
50| {
51| bool bOpened = true;
52|
53| try
54| {
55| oDoc = new XmlDocument();
56| oDoc.Load(sApps_Parameter_File);
57| oNodeReader = new XmlNodeReader(oDoc);
58|
59| //Allocate objects in the User_Class
60| oApp = new Apps_Class[Apps_Class.iMaxAppObjects];
61| }
62| catch
63| {
64| bOpened = false;
65| }
66|
67| return bOpened;
68| }
69|
70| //read each xml drives file
71| public void Read_Drive_Nodes()
72| {
73| string sElement = "";
74|
75| //Read the file
76| while (oNodeReader.Read())
77| {
78| //bypass the prologue
79| if (XmlNodeType.XmlDeclaration == oNodeReader.NodeType)
80| {
81| continue;
82| }
83|
84| //bypass any comment line
85| if (XmlNodeType.Comment == oNodeReader.NodeType)
86| {
87| continue;
88| }
89|
90| //Identify and store element name
91| if (XmlNodeType.Element == oNodeReader.NodeType)
92| {
93| sElement = oNodeReader.Name;
94| }
95|
96| //Process user node content
97| if (XmlNodeType.Text == oNodeReader.NodeType)
98| {
99| if (sElement.Equals("path"))
100| {
101|
sXml_Path = oNodeReader.Value;
102| }
103|
104| if (sElement.Equals("description"))
105| {
106|
sXml_Description = oNodeReader.Value;
107| }
108|
109| if (sElement.Equals("start_in"))
110| {
111| sXml_Start_in = oNodeReader.Value;
112| }
113|
114| if (sElement.Equals("parameter"))
115| {
116| sXml_Parameter = oNodeReader.Value;
117| }
118|
119| }//end of if
120|
121| //test if all content for user node has been read
122| if (XmlNodeType.EndElement == oNodeReader.NodeType)
123| {
124| if (oNodeReader.Name.Equals("app"))
125| {
126| Add_Object();
127| }
128| }
129|
130| }//end of while
131|
132| oNodeReader.Close();
133|
134| }//end of method
135|
136| //add an object to the user class
137| private void Add_Object()
138| {
139| //Is there room for another object?
140| //Can we instantiate more objects?
141| if (Apps_Class.iNextAppObj < Apps_Class.iMaxAppObjects)
142| {
143| oUser[Apps_Class.iNextAppObj] =
144| new Apps_Class(sXml_Path, sXml_Description, sXml_Start_in, sXml_Parameter);
145|
146| //Clear out the holding area fields
147| sXml_Path = "";
148| sXml_Description = "";
149| sXml_Start_in = "";
150| sXml_Parameter = "";
151| }
152|
153| }
154| }//end of class
155|
156| }