/// <summary>Processes XML represented by string and sets up the author and files information</summary> /// <param name="XML">Specifies the XML string to process</param> public bool ProcessXMLString(string XML) { try { // clear old XMLs information TestDrivers.Clear(); Libraries.Clear(); TestRequest = ""; Author = ""; // parse the text as XML xDoc = XDocument.Parse(XML); TestRequest = xDoc.Descendants("testRequest").First().Attribute("name").Value; // get the test author Author = xDoc.Descendants("author").First().Value; foreach (var Test in xDoc.Descendants("test")) { TestDrivers.Add(Test.Attribute("name").Value, new List <string>()); Libraries.Add(Test.Attribute("name").Value, new List <string>()); // get the Test Drivers indicated by the XML foreach (var node in Test.Descendants("testDriver")) { TestDrivers[Test.Attribute("name").Value].Add(node.Value); } // get the required Libraries indicated by the XML foreach (var node in Test.Descendants("library")) { Libraries[Test.Attribute("name").Value].Add(node.Value); } } return(true); } catch (Exception) { Console.Write("\n A problem occured while processing the XML string"); return(false); } }
/* ----------------------------------< Processing Region >---------------------------------- */ #region /// <summary>Processes XML file and sets-up the required files and the author name</summary> /// <param name="XMLPath">Specifies XML file path to process</param> public bool ProcessXMLFile(string XMLPath) { // Check if file exists if (File.Exists(XMLPath)) { TestDrivers.Clear(); Libraries.Clear(); TestRequest = ""; Author = ""; try { // load the XML xDoc = XDocument.Load(XMLPath); TestRequest = xDoc.Descendants("testRequest").First().Attribute("name").Value; // set the author to the author indicated by the XML Author = xDoc.Descendants("author").First().Value; foreach (var Test in xDoc.Descendants("test")) { TestDrivers.Add(Test.Attribute("name").Value, new List <string>()); Libraries.Add(Test.Attribute("name").Value, new List <string>()); // get the Test Drivers indicated by the XML foreach (var node in Test.Descendants("testDriver")) { TestDrivers[Test.Attribute("name").Value].Add(node.Value); } // get the required Libraries indicated by the XML foreach (var node in Test.Descendants("library")) { Libraries[Test.Attribute("name").Value].Add(node.Value); } } return(true); } catch (Exception) { Console.Write("\n A problem occured while processing {0}", Path.GetFileName(XMLPath)); return(false); } } else { Console.Write("\n Unable to find {0}. File does not exist", Path.GetFileName(XMLPath)); return(false); } }