How to write Xpath to extract total Quantity in C#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I am new in writing Xpath in C# and i am not able to get Sum of Quantity from xml data. i.e i want to get total quantity from multiple lines elements as in one unit of data.
The following xml shows some sample xml data :
<lines><br/>
<line><br/>
<line_no>11</line_no><br/>
<qty>50</qty><br/>
</line><br/>
<line><br/>
<line_no>12</line_no><br/>
<qty>150</qty><br/>
</line><br/>
<line><br/>
<line_no>13</line_no><br/>
<qty>100</qty><br/>
</line><br/>
<line><br/>
<line_no>14</line_no><br/>
<qty>90</qty><br/>
</line><br/>
<line><br/>
<line_no>15</line_no><br/>
<qty>40</qty><br/>
</line><br/>
</lines>

for the above code i have written Xpath like:
int total=SelectSingleNode("/lines/line/qty").Value;
By this i am getting only first line element quantity but i need to get all lines quantity i think here i need to Loop the lines of data if yes please help me how to write the xpath query.

Thanks,
Raghu.

<br/>


View the full article
 
Back
Top