如何从XML获取值 [英] How to get the values from XML
本文介绍了如何从XML获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨专家..
我有一个XML文件。
Hi experts..
I have one XML file.
<Rating>
<RatingInterval>1</RatingInterval>
<RatingCount>18</RatingCount>
</Rating>
<Rating>
<RatingInterval>2</RatingInterval>
<RatingCount>4</RatingCount>
</Rating>
<Rating>
<RatingInterval>3</RatingInterval>
<RatingCount>20</RatingCount>
</Rating>
<Rating>
<RatingInterval>4</RatingInterval>
<RatingCount>5</RatingCount>
</Rating>
<Rating>
<RatingInterval>5</RatingInterval>
<RatingCount>7</RatingCount>
</Rating>
</Rating>
我的要求是必须计算每个评级间隔的评级数。
评级间隔1 = 18
评级间隔2 = 4
评分间隔3 = 20
评级间隔4 = 5
评级时间间隔5 = 7
有很多< rating>标签。我必须提取所有数据。请帮帮我,如何提取值。
My requirement is have to calculate how many rating count for every rating interval.
Rating Interval 1 = 18
Rating Interval 2 = 4
Rating Interval 3 = 20
Rating Interval 4 = 5
Rating Interval 5 = 7
There is lots of <rating> tags. I have to extract all the data. Please help me, How to extract the values.
推荐答案
Dim rating As XElement = XElement.Parse(你的XML在这里)
对于每个ele in ratings.Elements
Console.WriteLine(评级间隔& ele。< ratinginterval> .Value&=& ele。< ratingcount> .Value)
下一页
Console.ReadLine()
Dim ratings As XElement = XElement.Parse("YOUR XML HERE")
For Each ele In ratings.Elements
Console.WriteLine("Rating Interval " & ele.<ratinginterval>.Value & " = " & ele.<ratingcount>.Value)
Next
Console.ReadLine()
这篇关于如何从XML获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文