日期:2014-05-18 浏览次数:20848 次
- <dsobject handle="Document-1480477" classname="Document" baseClassname="Document"> - <props> <prop name="DocumentTypeDesc" type="10">Herry-jack</prop> </props> </dsobject>
var query = from dsobject in document.Descendants("dsobject") where dsobject.Attribute("classname").Value == "Document" select new { DocID = new { Id = dsobject.Attribute("handle").Value, }, DocumentTypeDesc = from prop in dsobject.Descendants("prop") where prop.Attribute("name").Value == "DocumentTypeDesc" select new { Val = prop.Value } } //----------------------------------------------- string docid = item.DocID.Id; string dt = item.DocumentTypeDesc.First().Val; //-----------------------------------------------
//原代码写的有点画蛇添足了,简单写成这样就可以 var query = from dsobject in document.Descendants("dsobject") where dsobject.Attribute("classname").Value == "Document" select new { Id = dsobject.Attribute("handle").Value, }, DocumentTypeDesc = from prop in dsobject.Descendants("prop") where prop.Attribute("name").Value == "DocumentTypeDesc" select prop.Value }