簡體   English   中英

使用LINQ to XML更改或解析CRM FetchXML

[英]Change or parse CRM FetchXML with LINQ to XML

我有一個CRM FetchXML字符串。 這有一個鏈接實體,這意味着XML元素以GUID為前綴,例如:

 <a_6dd7d25cb0be4150bbaec7c0d2f430c7.lastname>Bob</a_6dd7d25cb0be4150bbaec7c0d2f430c7.lastname>
 <a_6dd7d25cb0be4150bbaec7c0d2f430c7.firstname>Bob</a_6dd7d25cb0be4150bbaec7c0d2f430c7.firstname> 
 <a_6dd7d25cb0be4150bbaec7c0d2f430c7.title name="Mr" formattedvalue="1">1</a_6dd7d25cb0be4150bbaec7c0d2f430c7.title> 

我想以類似於此的方式使用它:

List<FetchResult> results =
            (from result in xmlDoc.Descendants("result")
             select new FetchResult
             {
                 FirstName = result.Element("firstname").Value
             }).ToList<FetchResult>();

顯然這不起作用,所以無論如何我可以做一個Element.Contains("lastname")或類似的? 如果沒有,有沒有辦法可以手工解析我的字符串? 也許正則表達式?

謝謝

List<FetchResult> results =
            (from result in xmlDoc.Descendants("result")
             select new FetchResult
             {
                 FirstName = result.Elements().First(el => el.EndsWith("firstname")).Value
             }).ToList<FetchResult>();

應該管用

感謝Foo42 - 這是更新的語法

FirstName = result.Elements().First(el => el.Name.ToString().EndsWith("firstname")).Value

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM