XML 要素から値を取得し、それを使用していくつかの数式を実行できるように、linq コマンドを使用して整数に変換しようとしています。
これは私がこれまでに試した方法です:
private void buttonTab4Mod1Calculate_Click(object sender, EventArgs e)
{
var document = XDocument.Load(workingDir + @"\Level4.xml");
var assessmentOneWeight = from d in document.Descendants("moduleTitle")
where d.Value == (String)comboBoxTab4Mod8.SelectedItem
select d.Parent.Element("assessmentOneWeight").Value;
int a = 0;
foreach (var item in assessmentOneWeight)
{
a = Convert.ToInt32(item);
}
MessageBox.Show(a.ToString());
}
しかし、何らかの理由で値はまだ0です。
これは私のxmlファイルです:
<?xml version="1.0" encoding="utf-8" ?>
<SoftwareEngineering>
<Module>
<moduleCode>ECSE401</moduleCode>
<moduleTitle>Programming Methodology</moduleTitle>
<credits>15</credits>
<assessmentOne>Coursework</assessmentOne>
<assessmentOneWeight>40</assessmentOneWeight>
<assessmentTwo>Coursework</assessmentTwo>
<assessmentTwoWeight>40</assessmentTwoWeight>
<assessmentThree>Test</assessmentThree>
<assessmentThreeWeight>20</assessmentThreeWeight>
</Module>
<Module>
<moduleCode>ECSC404</moduleCode>
<moduleTitle>Computer Systems Fundamentals</moduleTitle>
<credits>15</credits>
<assessmentOne>Test1</assessmentOne>
<assessmentOneWeight>30</assessmentOneWeight>
<assessmentTwo>Test2</assessmentTwo>
<assessmentTwoWeight>30</assessmentTwoWeight>
<assessmentThree>Test3</assessmentThree>
<assessmentThreeWeight>40</assessmentThreeWeight>
</Module>
<Module>
<moduleCode>EBSY401</moduleCode>
<moduleTitle>Information and Data Modelling</moduleTitle>
<credits>15</credits>
<assessmentOne>Test</assessmentOne>
<assessmentOneWeight>25</assessmentOneWeight>
<assessmentTwo>Coursework1</assessmentTwo>
<assessmentTwoWeight>10</assessmentTwoWeight>
<assessmentThree>Coursework2</assessmentThree>
<assessmentThreeWeight>35</assessmentThreeWeight>
<assessmentFour>Coursework3</assessmentFour>
<assessmentFourWeight>30</assessmentFourWeight>
</Module>
<Module>
<moduleCode>ECSC405</moduleCode>
<moduleTitle>Software Development Principles</moduleTitle>
<credits>15</credits>
<assessmentOne>Test1</assessmentOne>
<assessmentOneWeight>30</assessmentOneWeight>
<assessmentTwo>Coursework</assessmentTwo>
<assessmentTwoWeight>40</assessmentTwoWeight>
<assessmentThree>Test2</assessmentThree>
<assessmentThreeWeight>30</assessmentThreeWeight>
</Module>
<Module>
<moduleCode>ECSC407</moduleCode>
<moduleTitle>Web Technology</moduleTitle>
<credits>15</credits>
<assessmentOne>Tutorials</assessmentOne>
<assessmentOneWeight>20</assessmentOneWeight>
<assessmentTwo>Coursework</assessmentTwo>
<assessmentTwoWeight>20</assessmentTwoWeight>
<assessmentThree>Exam</assessmentThree>
<assessmentThreeWeight>60</assessmentThreeWeight>
</Module>
<Module>
<moduleCode>ECSC409</moduleCode>
<moduleTitle>Software Engineering Principles</moduleTitle>
<credits>15</credits>
<assessmentOne>Coursework1</assessmentOne>
<assessmentOneWeight>40</assessmentOneWeight>
<assessmentTwo>Coursework2</assessmentTwo>
<assessmentTwoWeight>30</assessmentTwoWeight>
<assessmentThree>Coursework3</assessmentThree>
<assessmentThreeWeight>30</assessmentThreeWeight>
</Module>
<Module>
<moduleCode>ECSC408</moduleCode>
<moduleTitle>Mathematics for Computing</moduleTitle>
<credits>15</credits>
<assessmentOne>Coursework</assessmentOne>
<assessmentOneWeight>50</assessmentOneWeight>
<assessmentTwo>Exam</assessmentTwo>
<assessmentTwoWeight>50</assessmentTwoWeight>
</Module>
<Module>
<moduleCode>EBSY400</moduleCode>
<moduleTitle>Communication and Learning Skills</moduleTitle>
<credits>15</credits>
<assessmentOne>Coursework</assessmentOne>
<assessmentOneWeight>30</assessmentOneWeight>
<assessmentTwo>Coursework</assessmentTwo>
<assessmentTwoWeight>70</assessmentTwoWeight>
</Module>
</SoftwareEngineering>
助けていただければ幸いです。