[英]Change or parse CRM FetchXML with LINQ to XML
I have a CRM FetchXML string. 我有一个CRM FetchXML字符串。 This has a linked entity which means the XML Elements are prefixed with a GUID, such as:
这有一个链接实体,这意味着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>
I would like to use it in a way similar to this: 我想以类似于此的方式使用它:
List<FetchResult> results =
(from result in xmlDoc.Descendants("result")
select new FetchResult
{
FirstName = result.Element("firstname").Value
}).ToList<FetchResult>();
Obviously this won't work, so is there anyway I can do a Element.Contains("lastname")
or similar? 显然这不起作用,所以无论如何我可以做一个
Element.Contains("lastname")
或类似的? If not, is there way I can parse this out of my string before hand? 如果没有,有没有办法可以手工解析我的字符串? Perhaps regex?
也许正则表达式?
Thanks 谢谢
List<FetchResult> results =
(from result in xmlDoc.Descendants("result")
select new FetchResult
{
FirstName = result.Elements().First(el => el.EndsWith("firstname")).Value
}).ToList<FetchResult>();
Should work 应该管用
感谢Foo42
- 这是更新的语法
FirstName = result.Elements().First(el => el.Name.ToString().EndsWith("firstname")).Value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.