I am getting invalid XML error can anyone help me
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Query;
using System.Web.UI.WebControls;
using Microsoft.Xrm.Sdk.WebServiceClient;
namespace postoperationonaccount
{
public class postoperation : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
try
{
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "account")
{
var leadoriginid = entity.GetAttributeValue<EntityReference>("originatingleadid").Id;
Console.WriteLine(leadoriginid);
if (leadoriginid != null)
{
StringBuilder fetch = new StringBuilder();
fetch.Append("<fetch version='1.0' output-format='xml - platform' mapping='logical' distinct='true'>");
fetch.Append(" <entity name='competitor'>");
fetch.Append("<attribute name='name' />");
fetch.Append("<attribute name='websiteurl' />");
fetch.Append("<attribute name='competitorid' />");
fetch.Append("<order attribute='name' descending='false' />");
fetch.Append("<link-entity name='leadcompetitors' from='competitorid' to='competitorid' visible='false' intersect='true'>");
fetch.Append("<link-entity name='lead' from='leadid' to='leadid' alias='ag'>");
fetch.Append("<filter type='and'>");
fetch.Append("<condition attribute='leadid' operator='eq' value='{"+leadoriginid.ToString()+"}' />");
fetch.Append("</ filter>");
fetch.Append("</link-entity>");
fetch.Append("</link-entity>");
fetch.Append("</entity>");
fetch.Append("</fetch>");
// var query=string.Format(fetchxml, leadoriginid.ToString());
EntityCollection competitorresult = service.RetrieveMultiple(new FetchExpression(fetch.ToString()));
Console.WriteLine(competitorresult);
var relatedentities = new EntityReferenceCollection();
foreach (var e in competitorresult.Entities)
{
relatedentities.Add(new EntityReference("competitor", e.Id));
}
var relationship = new Relationship("sb_competitor_account");
Guid entityid = entity.Id;
service.Associate("account", entityid, relationship, relatedentities);
}
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
}
}