Неверный XML. --- & gt на плагине, содержащем FetchXML - PullRequest
0 голосов
/ 11 ноября 2018

Это происходит, когда в имени контракта есть & или другие недопустимые символы. У меня вопрос, как мне справиться с этими недопустимыми символами ?? !!

Microsoft.Crm.CrmException: Неверный XML. ---> System.Xml.XmlException: при синтаксическом анализе EntityName произошла ошибка. Строка 13, позиция 117 . в System.Xml.XmlTextReaderImpl.Throw (исключение 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, параметры LoadOptions) в Microsoft.Crm.Platform.Server.Utility.XmlHelper.LoadXmlInfo (String xmlInfo) в Microsoft.Crm.Query.EntityExpression.ExtractPlatformName (String fetchXml, элемент XElement).

Вот код в вопросах:

//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));

Ответы [ 2 ]

0 голосов
/ 12 ноября 2018

uiname и uitype не требуются для работы fetchXml. Они используются для представления, а не для запроса. Я думаю, что они добавлены редактором Advanced Find; следовательно "UI"

Вы можете переписать этот раздел 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>";
0 голосов
/ 12 ноября 2018

Я использовал webutility.htmlencode(uiname), и проблема, похоже, исчезла. Я полагаю, что в имени пользователя есть недопустимые символы XML, и этот метод избавляет от проблемы!

...