我想获得的价值我的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>
将不胜感激一些帮助。