dynamics-crm - 无效的 XML。---> 在包含 FetchXML 的插件上
问题描述
当合同名称中有 & 或其他无效字符时,就会发生这种情况。我的问题是,我该如何处理这些无效字符??!!
Microsoft.Crm.CrmException:无效的 XML。---> System.Xml.XmlException: 解析 EntityName 时出错。第 13 行,位置 117. 在 System.Xml.XmlTextReaderImpl.Throw(Exception e) 在 System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos) 在 System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr) 在 System .Xml.XmlTextReaderImpl.ParseAttributes() 在 System.Xml.XmlTextReaderImpl.ParseElement() 在 System.Xml.XmlTextReaderImpl.ParseElementContent() 在 System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r) 在 System.Xml.Linq.XContainer .ReadContentFrom(XmlReader r, LoadOptions o) 在 System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options) 在 Microsoft.Crm.Platform.Server.Utility.XmlHelper.LoadXmlInfo(String xmlInfo) 在 Microsoft.Crm.Query .EntityExpression。
这是有问题的代码:
//run a fetchXml query to get how many contract lines have these values
string fetchLines = @"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='new_yummycontractline'>
<attribute name='new_yummycontractlineid' />
<filter type='and'>
<condition attribute='new_servingtime' operator='eq' value='" + servingTime.ToString() + @"' />
<condition attribute='new_servinggroup' operator='eq' value='" + servingGroup.ToString() + @"' />
<condition attribute='new_destination' operator='eq' value='" + location.ToString() + @"' />
<condition attribute='statecode' operator='eq' value='0' />
</filter>
<link-entity name='new_yummycontract' from='new_yummycontractid' to='new_contractid' link-type='inner' alias='ad'>
<filter type='and'>
<condition attribute='new_yummycontractid' operator='eq' uiname='" + uiname + @"' uitype='new_yummycontract' value='" + contractId.ToString() + @"' />
</filter>
</link-entity>
</entity>
</fetch>";
EntityCollection results = service.RetrieveMultiple(new FetchExpression(fetchLines));
解决方案
uiname
并且uitype
不是您的 fetchXml 工作所必需的。这些用于演示而不是用于查询。我认为这些是由高级查找编辑器添加的;因此“用户界面”
您可以像这样重写 XML 的那部分
<link-entity name='new_yummycontract' from='new_yummycontractid' to='new_contractid' link-type='inner' alias='ad'>
<filter type='and'>
<condition attribute='new_yummycontractid' operator='eq' value='" + contractId.ToString() + @"' />
</filter>
</link-entity>
不确定您使用的是哪个版本的 .NET,但您也可以使用$
特殊字符来指示插值字符串,我认为这可以提高可读性并减少字符串连接
string fetchLines = @$"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='new_yummycontractline'>
<attribute name='new_yummycontractlineid' />
<filter type='and'>
<condition attribute='new_servingtime' operator='eq' value='{servingTime}' />
<condition attribute='new_servinggroup' operator='eq' value='{servingGroup}' />
<condition attribute='new_destination' operator='eq' value='{location}' />
<condition attribute='statecode' operator='eq' value='0' />
</filter>
<link-entity name='new_yummycontract' from='new_yummycontractid' to='new_contractid' link-type='inner' alias='ad'>
<filter type='and'>
<condition attribute='new_yummycontractid' operator='eq' value='{contractId}' />
</filter>
</link-entity>
</entity>
</fetch>";
推荐阅读
- python - 使用 pred 框坐标裁剪图像
- mongodb - oplog 收集在 mongodb 中是如何工作的?
- sympy - MatrixSymbol 上的符号减少
- android - Android firebase 通知,BigPicture 和 BigContentTitle
- python - 关于字符串中的循环和最终序列的代码问题
- java - 如何解决“只能注入其中一种
进入@AfterTest”异常 - javascript - 发送列索引到排序函数
- c# - MassTransit Consumer 在进行依赖注入时不消费消息
- c# - 将字符串存储在第一次后不会更改的 c# 应用程序中
- python - 在将数据转换为设计矩阵时检索 patsy 的级别和分类变量的编码