你如何解析FetchXML请求的结果?

时间:2011-09-18 09:45:03

标签: dynamics-crm-4 crm fetchxml

我如何解析以下FetchXML请求的结果?

string fetch_checkEntity = @"
     <fetch mapping='logical'>
       <entity name='" + entityname + @"'>
         <attribute name='" + columnname + @"' />
         <attribute name='" + logicalnameid + @"' />
         <order attribute='" + columnname + @"' />
           <filter>
             <condition attribute='statecode' operator='eq' value='0' />
             <condition attribute='statuscode' operator='eq' value='1' />
           </filter>
         </entity>
       </fetch>";

string result_checkEntity = crmService.Fetch(fetch_checkEntity);

1 个答案:

答案 0 :(得分:0)

我建议使用XDocument功能来解析fetch语句的结果 我不确切知道resultset的确切外观,但这里有一些关于如何进行解析的提示。

XDocument xml = XDocument.Parse(result_checkEntity);  

var results = from item in xml.Elements("result")  
               select new  // creating an anonymous type
               {  
                   element = (type of value) //casting operation to what you have: string, Guid, etc
                             item.Element("  ") // in the paranthesis put the name 
                                                // of the element you are interesting 
                                                // in getting back; columnname 
               };