EDN Admin
Well-known member
Hi,
I am having trouble getting the maximum value of an attribute as an integer.
Given this xml, how can a LINQ to XML query return 51. (The max as an integer).
<xmlroot><element1 Value="8" ></element1><element1 Value="11 </element1><element1 Value="51 </element1></xmlroot>
My query so far:
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
var
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small m =
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small from<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
a <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small in<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
doc.Elements(<span style="font-family:Consolas; color:#dc1414; font-size:x-small <span style="font-family:Consolas; color:#dc1414; font-size:x-small <span style="font-family:Consolas; color:#dc1414; font-size:x-small "element1"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ).Max(l
=> l.Attribute(<span style="font-family:Consolas; color:#dc1414; font-size:x-small <span style="font-family:Consolas; color:#dc1414; font-size:x-small <span style="font-family:Consolas; color:#dc1414; font-size:x-small "Value"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ).Value)
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small select<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
m;
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small This returns 8 as an IEnumerable<char>.
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small thanks,
<span style="font-family:Consolas; font-size:x-small sivilian
<span style="font-family:Consolas; font-size:x-small
View the full article
I am having trouble getting the maximum value of an attribute as an integer.
Given this xml, how can a LINQ to XML query return 51. (The max as an integer).
<xmlroot><element1 Value="8" ></element1><element1 Value="11 </element1><element1 Value="51 </element1></xmlroot>
My query so far:
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
var
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
</font></font><font face="Consolas" size="2" color="#0000ff
</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small m =
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small from<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
a <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small in<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
doc.Elements(<span style="font-family:Consolas; color:#dc1414; font-size:x-small <span style="font-family:Consolas; color:#dc1414; font-size:x-small <span style="font-family:Consolas; color:#dc1414; font-size:x-small "element1"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ).Max(l
=> l.Attribute(<span style="font-family:Consolas; color:#dc1414; font-size:x-small <span style="font-family:Consolas; color:#dc1414; font-size:x-small <span style="font-family:Consolas; color:#dc1414; font-size:x-small "Value"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ).Value)
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small select<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
m;
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small This returns 8 as an IEnumerable<char>.
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small thanks,
<span style="font-family:Consolas; font-size:x-small sivilian
<span style="font-family:Consolas; font-size:x-small
View the full article