LINQ to XML 使用总和进行分组
我目前正在使用这个 xml(这是一个小子集):
<?xml version="1.0" encoding="UTF-8"?>
<orders>
<order>
<customer><![CDATA[1035]]></customer>
<total><![CDATA[10]]></total>
</order>
<order>
<customer><![CDATA[1036]]></customer>
<total><![CDATA[5.6]]></total>
</order>
<order>
<customer><![CDATA[1035]]></customer>
<total><![CDATA[5.6]]></total>
</order>
</orders>
我试图弄清楚是否有一种方法可以按客户对其进行分组并对总数进行求和。
当我迭代分组时,我会:
customer 1035 with a total of 15.6
customer 1036 with a total of 5.6
I am currently working with this xml (this is a small subset):
<?xml version="1.0" encoding="UTF-8"?>
<orders>
<order>
<customer><![CDATA[1035]]></customer>
<total><![CDATA[10]]></total>
</order>
<order>
<customer><![CDATA[1036]]></customer>
<total><![CDATA[5.6]]></total>
</order>
<order>
<customer><![CDATA[1035]]></customer>
<total><![CDATA[5.6]]></total>
</order>
</orders>
I am trying to figure out if there is a way to group this by customer and sum the total.
When I iterate through groupings I would have:
customer 1035 with a total of 15.6
customer 1036 with a total of 5.6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会首先进行变换,然后进行分组/求和:(
当然,您也可以用点表示法完成所有这些操作。)
I would first transform, then group/sum:
(You could do all of this in dot notation as well, of course.)