as I said I have a set of Xml Nodes, each node have an attribute called ows_ID, now I want to search for an node having max ows_ID.
<listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<rs:data ItemCount="5">
<z:row ows_DocIcon="txt" ows_LinkFilename="Hello.txt" ows_Modified="2011-05-26 19:55:07" ows_Editor="1;#MANGESH\Administrator" ows_ID="19" ows_Title="JhallanPandey" ows_MetaInfo="19;#vti_parserversion:SR|12.0.0.6219 vti_modifiedby:SR|MANGESH\\administrator ContentTypeId:SW|0x010100FBA6D2C6515E404EB6938D8E73143637 vti_author:SR|MANGESH\\administrator " ows__ModerationStatus="0" ows__Level="1" ows_Last_x0020_Modified="19;#2011-05-26 19:55:07" ows_owshiddenversion="3" ows_UniqueId="19;#{1702B333-8CA1-4CA5-BA41-A2E761312019}" ows_FSObjType="19;#0" ows_Created_x0020_Date="19;#2011-05-26 19:52:32" ows_ProgId="19;#" ows_FileLeafRef="19;#Hello.txt" ows_FileRef="19;#Documents/Hello.txt" />
<z:row ows_DocIcon="zip" ows_LinkFilename="LocalMachineService.zip" ows_Modified="2011-05-26 19:41:23" ows_Editor="1;#MANGESH\Administrator" ows_ID="17" ows_MetaInfo="17;#vti_parserversion:SR|12.0.0.6219 vti_modifiedby:SR|MANGESH\\administrator ContentTypeId:SW|0x010100FBA6D2C6515E404EB6938D8E73143637 vti_author:SR|MANGESH\\administrator " ows__ModerationStatus="0" ows开发者_StackOverflow社区__Level="1" ows_Last_x0020_Modified="17;#2011-05-26 19:41:23" ows_owshiddenversion="8" ows_UniqueId="17;#{F5EED71F-A2FC-460D-AC1C-456ED51DC9B4}" ows_FSObjType="17;#0" ows_Created_x0020_Date="17;#2011-05-26 19:26:39" ows_ProgId="17;#" ows_FileLeafRef="17;#LocalMachineService.zip" ows_FileRef="17;#Documents/LocalMachineService.zip" />
<z:row ows_DocIcon="txt" ows_LinkFilename="momo.txt" ows_Modified="2011-05-26 20:16:18" ows_Editor="1;#MANGESH\Administrator" ows_ID="20" ows_MetaInfo="20;#vti_parserversion:SR|12.0.0.6219 vti_modifiedby:SR|MANGESH\\administrator ContentTypeId:SW|0x010100FBA6D2C6515E404EB6938D8E73143637 vti_author:SR|MANGESH\\administrator " ows__ModerationStatus="0" ows__Level="1" ows_Last_x0020_Modified="20;#2011-05-26 20:16:19" ows_owshiddenversion="2" ows_UniqueId="20;#{E21E7892-D653-46CE-B561-2A5812ACE6DC}" ows_FSObjType="20;#0" ows_Created_x0020_Date="20;#2011-05-26 20:05:28" ows_ProgId="20;#" ows_FileLeafRef="20;#momo.txt" ows_FileRef="20;#Documents/momo.txt" />
<z:row ows_DocIcon="txt" ows_LinkFilename="MUSKAAN.txt" ows_Modified="2011-05-27 16:05:55" ows_Editor="1;#MANGESH\Administrator" ows_ID="21" ows_MetaInfo="21;#vti_parserversion:SR|12.0.0.6219 vti_modifiedby:SR|MANGESH\\administrator ContentTypeId:SW|0x010100FBA6D2C6515E404EB6938D8E73143637 vti_author:SR|MANGESH\\administrator " ows__ModerationStatus="0" ows__Level="1" ows_Last_x0020_Modified="21;#2011-05-27 16:05:56" ows_owshiddenversion="9" ows_UniqueId="21;#{F3F3D617-5A3F-4939-98CC-3B74F1BB228F}" ows_FSObjType="21;#0" ows_Created_x0020_Date="21;#2011-05-26 20:23:57" ows_ProgId="21;#" ows_FileLeafRef="21;#MUSKAAN.txt" ows_FileRef="21;#Documents/MUSKAAN.txt" />
<z:row ows_DocIcon="txt" ows_LinkFilename="test.txt" ows_Modified="2011-05-26 19:58:21" ows_Editor="1;#MANGESH\Administrator" ows_ID="18" ows_MetaInfo="18;#vti_parserversion:SR|12.0.0.6219 vti_modifiedby:SR|MANGESH\\administrator ContentTypeId:SW|0x010100FBA6D2C6515E404EB6938D8E73143637 vti_author:SR|MANGESH\\administrator " ows__ModerationStatus="0" ows__Level="1" ows_Last_x0020_Modified="18;#2011-05-26 19:58:21" ows_owshiddenversion="4" ows_UniqueId="18;#{378A6851-77BA-4BBC-96F0-612A78C39E44}" ows_FSObjType="18;#0" ows_Created_x0020_Date="18;#2011-05-26 19:45:14" ows_ProgId="18;#" ows_FileLeafRef="18;#test.txt" ows_FileRef="18;#Documents/test.txt" />
</rs:data>
<listitems
Thanx
Okay, I would use LINQ to XML and probably MaxBy
from MoreLINQ:
XElement doc = XElement.Load(...); // Insert your filename or whatever here
XNamespace z = "#RowsetSchema";
XElement max = doc.Descendants(z + "row")
.MaxBy(x => (int) x.Attribute("ows_ID"));
Alternatively, without MoreLINQ:
XElement doc = XElement.Load(...); // Insert your filename or whatever here
XNamespace z = "#RowsetSchema";
int maxId = doc.Descendants(z + "row")
.Max(x => (int) x.Attribute("ows_ID"));
XElement max = doc.Descendants(z + "row")
.First(x => (int) x.Attribute("ows_ID") == maxId);
Maybe this helps:
XElement element = XElement.Load("Your.xml");
int max = element.Elements("Element").Max(l => int.Parse(l.Attribute("ItemId").Value));
XmlNode node = xmlDocument.SelectSingleNode("Element[@ItemId='" + max+"']");
精彩评论