将 XElement 分组到 Linq to XML 中的集合中?
这是一个 XML 示例:
<ProblemFactory Name="Diagnostic exam" Count="1">
<Condition ObjectiveID="1" Type="1" CountRanges="2" Range1Decimals="0" Range1Min="3" Range1Max="10" Range2Decimals="0" Range2Min="6" Range2Max="10" />
<Condition ObjectiveID="1" Type="1" CountRanges="2" Range1Decimals="0" Range1Min="6" Range1Max="10" Range2Decimals="0" Range2Min="6" Range2Max="10" />
</ProblemFactory>
我正在尝试执行如下操作:
XDocument xdoc = XDocument.Load("ProblemFactory.xml");
var problems = from pf in xdoc.Descendants("Condition")
select new
{
// ObjectiveID property
// Type property
// Ranges collection property
};
创建范围集合是我的问题。如何构建 XML 文件或查询来创建集合?该集合将包含:RangeDecimals、RangeMin、RangeMax。
我不确定,但我可以想象要解决这个问题,我必须重新构造我的条件元组:
<Condition ObjectiveID="1" Type="1" >
<RangesCollection>
<Range RangeDecimals="0" RangeMin="3" RangeMax="10" />
<Range RangeDecimals="0" RangeMin="6" RangeMax="10" />
</RangesCollection>
</Condition>
This is an XML example:
<ProblemFactory Name="Diagnostic exam" Count="1">
<Condition ObjectiveID="1" Type="1" CountRanges="2" Range1Decimals="0" Range1Min="3" Range1Max="10" Range2Decimals="0" Range2Min="6" Range2Max="10" />
<Condition ObjectiveID="1" Type="1" CountRanges="2" Range1Decimals="0" Range1Min="6" Range1Max="10" Range2Decimals="0" Range2Min="6" Range2Max="10" />
</ProblemFactory>
And I'm trying to do something like the following:
XDocument xdoc = XDocument.Load("ProblemFactory.xml");
var problems = from pf in xdoc.Descendants("Condition")
select new
{
// ObjectiveID property
// Type property
// Ranges collection property
};
Create the ranges collection is my problem. How can I strutured my XML file or query to create the collection? The collection will contain: RangeDecimals, RangeMin, RangeMax.
I'm not sure, but I can Imagine to solve this problem I've gotta reestruct my Condition tuple:
<Condition ObjectiveID="1" Type="1" >
<RangesCollection>
<Range RangeDecimals="0" RangeMin="3" RangeMax="10" />
<Range RangeDecimals="0" RangeMin="6" RangeMax="10" />
</RangesCollection>
</Condition>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
With the new format,
With the new format,