有人可以帮助我创建 LINQ to XML 查询吗?
我有三个类
ExamProduced:
+ ExamID
+ Date
+ Seed
+ Exercises
Exercise
+ Quantity
+ IsMakeUp
+ Score
+ Answers
Answer
+ IsCorrect
我有这个 Xml 文件
<Answers ExamID="1" StudentID="abcd" Date="10/26/2011 11:50:34 AM"
Seed="495" IsSED="False">
<Summary>
<Objective ID="1" MakeUp="False" Quantify="5"
Difficulty="Easy" Accredited="True" Produced="True">
<Details Result="0" Date="10/26/2011 11:35:18 AM" />
<Details Result="1" Date="10/26/2011 11:50:34 AM" />
</Objective>
<Objective ID="2" MakeUp="True" Quantify="5"
Difficulty="Easy" Accredited="False" Produced="True">
<Details Result="0" Date="10/26/2011 11:35:18 AM" />
<Details Result="0" Date="10/26/2011 11:50:34 AM" />
</Objective>
<Objective ID="3" MakeUp="True" Quantify="2"
Difficulty="Easy" Accredited="False" Produced="False">
<Details Result="0" Date="10/26/2011 11:35:18 AM" />
<Details Result="0" Date="10/26/2011 11:50:34 AM" />
</Objective>
</Summary>
<Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy">
<Result DataType="System.Decimal" Value="9" />
</Answer>
<Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy">
<Result DataType="System.Decimal" Value="20" />
</Answer>
<Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy">
<Result DataType="System.Decimal" Value="16" />
</Answer>
<Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy">
<Result DataType="System.Decimal" Value="36" />
</Answer>
<Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy">
<Result DataType="System.Decimal" Value="18" />
</Answer>
<Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy">
<Result DataType="System.Decimal" Value="Null" />
</Answer>
<Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy">
<Result DataType="System.Decimal" Value="Null" />
</Answer>
<Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy">
<Result DataType="System.Decimal" Value="Null" />
</Answer>
<Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy">
<Result DataType="System.Decimal" Value="Null" />
</Answer>
<Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy">
<Result DataType="System.Decimal" Value="Null" />
</Answer>
</Answers>
那么,我需要一些帮助来创建这个查询。 ExamProduced 属性可以通过 root 获取。然后在练习中,查看标签“Summary”,这里是历史记录。因此,我需要获取“Produced”属性为 true 的那些值。
例如,“producted”为 true 的两个目标是“objectiveId”1 和“2”。然后我需要获取数值数量并进行弥补(用于练习课)。然后就像 1 和 2 目标一样,每个目标都有我需要获得的值是否正确或错误的答案。
提前致谢。
编辑: 例如,在本例中,类应该具有:
ExamProduced
+ ExamID: 1
+ Date: 10/26/2011 11:50:34 AM
+ Seed: 495
+ Exercises: { 2 items }
{
Exercise
{
+ Quantity = 5
+ IsMakeUp = False;
+ Score = 1 (it means one hundred for Answers/Summary/Objective/LastDetail => Result)
+ Answers (5 items)
{
Answer
{
+ IsCorrect = true
}
Answer
{
+ Is...
}
Ans {..}
Ans {..}
Ans {..}
}
}
Exercise
{
...
}
}
I've got three classes
ExamProduced:
+ ExamID
+ Date
+ Seed
+ Exercises
Exercise
+ Quantity
+ IsMakeUp
+ Score
+ Answers
Answer
+ IsCorrect
And I've got this Xml file
<Answers ExamID="1" StudentID="abcd" Date="10/26/2011 11:50:34 AM"
Seed="495" IsSED="False">
<Summary>
<Objective ID="1" MakeUp="False" Quantify="5"
Difficulty="Easy" Accredited="True" Produced="True">
<Details Result="0" Date="10/26/2011 11:35:18 AM" />
<Details Result="1" Date="10/26/2011 11:50:34 AM" />
</Objective>
<Objective ID="2" MakeUp="True" Quantify="5"
Difficulty="Easy" Accredited="False" Produced="True">
<Details Result="0" Date="10/26/2011 11:35:18 AM" />
<Details Result="0" Date="10/26/2011 11:50:34 AM" />
</Objective>
<Objective ID="3" MakeUp="True" Quantify="2"
Difficulty="Easy" Accredited="False" Produced="False">
<Details Result="0" Date="10/26/2011 11:35:18 AM" />
<Details Result="0" Date="10/26/2011 11:50:34 AM" />
</Objective>
</Summary>
<Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy">
<Result DataType="System.Decimal" Value="9" />
</Answer>
<Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy">
<Result DataType="System.Decimal" Value="20" />
</Answer>
<Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy">
<Result DataType="System.Decimal" Value="16" />
</Answer>
<Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy">
<Result DataType="System.Decimal" Value="36" />
</Answer>
<Answer ProblemID="0" ObjectiveID="1" IsCorrect="True" Difficulty="Easy">
<Result DataType="System.Decimal" Value="18" />
</Answer>
<Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy">
<Result DataType="System.Decimal" Value="Null" />
</Answer>
<Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy">
<Result DataType="System.Decimal" Value="Null" />
</Answer>
<Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy">
<Result DataType="System.Decimal" Value="Null" />
</Answer>
<Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy">
<Result DataType="System.Decimal" Value="Null" />
</Answer>
<Answer ProblemID="0" ObjectiveID="2" IsCorrect="False" Difficulty="Easy">
<Result DataType="System.Decimal" Value="Null" />
</Answer>
</Answers>
Well, I need a bit of help to create this query. ExamProduced properties can get through the root. Then in exercise, take a look at the tag Summary, in this place is an historial.. so, I need to get those values where the attribute Produced is true.
For example, two objectives where produced is true are the 1 and 2 objectivesId. Then I need to get the values quantity and make up (for exercise class). Then like 1 and 2 objective were produced, each one has answers I need to get if the value was correct o wrong.
Thanks in advance.
EDIT:
For example at this case, the classes should have:
ExamProduced
+ ExamID: 1
+ Date: 10/26/2011 11:50:34 AM
+ Seed: 495
+ Exercises: { 2 items }
{
Exercise
{
+ Quantity = 5
+ IsMakeUp = False;
+ Score = 1 (it means one hundred for Answers/Summary/Objective/LastDetail => Result)
+ Answers (5 items)
{
Answer
{
+ IsCorrect = true
}
Answer
{
+ Is...
}
Ans {..}
Ans {..}
Ans {..}
}
}
Exercise
{
...
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我为您尝试构建的数据设计的稍微过度设计的解决方案。使用它:
以及实际实现:
Here's my slightly over-engineered solution for the data you're trying to build. To use it:
And the actual implementation:
如果我正确理解你的要求,类似这样的事情应该可以解决问题:
If I understood your requirements correctly, something like this should do the trick: