-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analysis.cs
60 lines (57 loc) · 1.9 KB
/
Analysis.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.IO;
using System.Data;
using System.Xml;
/// <summary>
/// The main class that processes all information
/// </summary>
///
namespace XMLAnalysis
{
public class Analysis
{
/// <summary>
/// Takes in a xml file in order to check that there are not multiple columns in the same row with data, as well as checking that
/// the only data inputted is '1'.
/// </summary>
/// <param name="table"></param>
/// The data in an xml document
/// <returns></returns>
public List<int> validateTable(XmlDocument data)
{
XmlNodeList tableNodes = data.SelectNodes("//NewDataSet/Table1");
int count = 0;
List<int> invalidNodes = new List<int>();
foreach (XmlNode itemNode in tableNodes)
{
count++;
Boolean conc1 = checkNode(itemNode.SelectSingleNode("Conc1Default"));
Boolean conc2 = checkNode(itemNode.SelectSingleNode("Conc2Default"));
Boolean conc3 = checkNode(itemNode.SelectSingleNode("Conc3Default"));
int testInt = boolToInt(conc1) + boolToInt(conc2) + boolToInt(conc3);
if (testInt != 1)
{
invalidNodes.Add(count);
}
}
return invalidNodes;
}
private Boolean checkNode(XmlNode itemNode)
{
String data = itemNode.SelectSingleNode("/text()").Value;
int dataTest;
if(Int32.TryParse(data, out dataTest))
{
if (dataTest == 1)
return true;
}
return false;
}
private int boolToInt(Boolean t)
{
int i = t ? 1 : 0;
return i;
}
}
}