Read_XML_Drives_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_Drives_Class
    13|     {
    14|         string sDrives_Parameter_File = "";
    15| 
    16|         //declare an array of objects
    17|         public Drives_Class[] oDrive;
    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| 
    27|         //constructor method
    28|         public Read_XML_Drives_Class(string sDrive_XML_File_Location)
    29|         {
    30|             //Set the location of this user's Drives XML file
    31|             sDrives_Parameter_File = sDrive_XML_File_Location;
    32|         }
    33| 
    34|         //does xml file exit?
    35|         public bool Parameter_File_Exist()
    36|         {
    37|             bool bExists = true;
    38| 
    39|             if (!File.Exists(sDrivess_Parameter_File))
    40|             {
    41|                 bExists = false;
    42|             }
    43|             return bExists;
    44|         }
    45| 
    46|         //open the xml file and declare an array of user objects
    47|         public bool Open_XML_Parameter_File()
    48|         {
    49|             bool bOpened = true;
    50| 
    51|             try
    52|             {
    53|                 oDoc = new XmlDocument();
    54|                 oDoc.Load(sDrives_Parameter_File);
    55|                 oNodeReader = new XmlNodeReader(oDoc);
    56| 
    57|                 //Allocate objects in the User_Class
    58|                 oDrive = new Drives_Class[Drives_Class.iMaxDriveObjects];
    59|             }
    60|             catch
    61|             {
    62|                 bOpened = false;
    63|             }
    64| 
    65|             return bOpened;
    66|         }
    67| 
    68|         //read each xml drives file
    69|         public void Read_Drive_Nodes()
    70|         {
    71|             string sElement = "";
    72| 
    73|             //Read the file
    74|             while (oNodeReader.Read())
    75|             {
    76|                 //bypass the prologue
    77|                 if (XmlNodeType.XmlDeclaration == oNodeReader.NodeType)
    78|                 {
    79|                     continue;
    80|                 }
    81| 
    82|                 //bypass any comment line
    83|                 if (XmlNodeType.Comment == oNodeReader.NodeType)
    84|                 {
    85|                     continue;
    86|                 }
    87| 
    88|                 //Identify and store element name
    89|                 if (XmlNodeType.Element == oNodeReader.NodeType)
    90|                 {
    91|                     sElement = oNodeReader.Name;
    92|                 }
    93| 
    94|                 //Process user node content
    95|                 if (XmlNodeType.Text == oNodeReader.NodeType)
    96|                 {
    97|                     if (sElement.Equals("path"))
    98|                     {
    99| 
                        sXml_Path = oNodeReader.Value;
  100|                     }
  101| 
  102|                     if (sElement.Equals("description"))
  103|                     {
  104| 
                        sXml_Description = oNodeReader.Value;
  105|                     }
  106| 
  107|                 }//end of if
  108| 
  109|                 //test if all content for user node has been read
  110|                 if (XmlNodeType.EndElement == oNodeReader.NodeType)
  111|                 {
  112|                     if (oNodeReader.Name.Equals("drive"))
  113|                     {
  114|                         Add_Object();
  115|                     }
  116|                 }
  117| 
  118|             }//end of while
  119| 
  120|             oNodeReader.Close();
  121| 
  122|         }//end of method
  123| 
  124|         //add an object to the user class
  125|         private void Add_Object()
  126|         {
  127|             //Is there room for another object?
  128|             //Can we instantiate more objects?
  129|             if (Apps_Class.iNextDriveObj < Apps_Class.iMaxDriveObjects)
  130|             {
  131|                 oUser[Apps_Class.iNextDriveObj] =
  132|                   new Apps_Class(sXml_Path, sXml_Description);
  133| 
  134|                 //Clear out the holding area fields
  135|                 sXml_Path = "";
  136|                 sXml_Description = "";
  137| 
  138|         }
  139|     }//end of class
  140| 
  141| }