I have a CRM FetchXML string. This has a linked entity which means the XML Elements are prefixed with a GUID, such as:
<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? 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.