I am totally out of Ideas and my C# / LINQ / XML skills are stills very weak. Maybe someone can help me with a relatively simple task that I don't want to write a whole programm around:
I need to get the Highest Customer-ID in an XML Database that looks somewhat like this:
<xml>
<customers>
<customer>
<customerid>a00001</customerid>
<name>this</name>
</customer>
<customer>
<customerid>a00031</customerid>
<name>that</name>
</customer>
and so on...
What I have tried so far is a mixture of code I have used for other linq/xml that actually worked, combined with stuff I found here:
var readme = XElement.Load("someXML");
int tempHigh;
var highIDs =
(from va in readme.Elements("customers").Elements("customer")
where Convert.ToInt32(va.Element("customerid").Value.Substring(2, 5)) > tempHigh
select Convert.ToInt32(va.Element("customerid").Value.Substring(2,5)));
tempHigh = Convert.ToInt32(highIDs.Element("customerid").Value);
return tempHigh;
And something is not working. Anyone have an idea where I don't have to put all the data in an array, sort that array and give out the first element (because that is my only Idea left but seems a bit too much)
Thanks in Advance!
No comments:
Post a Comment