Invalid XML. ---&gt On A Plugin Containing FetchXML









up vote
0
down vote

favorite












This happens when there is &, or other invalid characters in the contract name. My question is, how do I deal with these invalid characters??!!




Microsoft.Crm.CrmException: Invalid XML. --->
System.Xml.XmlException: An error occurred while parsing EntityName.
Line 13, position 117
.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32&
charRefEndPos)
at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at Microsoft.Crm.Platform.Server.Utility.XmlHelper.LoadXmlInfo(String
xmlInfo)
at Microsoft.Crm.Query.EntityExpression.ExtractPlatformName(String fetchXml, XElement element).




Here is the code in questions:





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











share|improve this question



























    up vote
    0
    down vote

    favorite












    This happens when there is &, or other invalid characters in the contract name. My question is, how do I deal with these invalid characters??!!




    Microsoft.Crm.CrmException: Invalid XML. --->
    System.Xml.XmlException: An error occurred while parsing EntityName.
    Line 13, position 117
    .
    at System.Xml.XmlTextReaderImpl.Throw(Exception e)
    at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32&
    charRefEndPos)
    at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
    at System.Xml.XmlTextReaderImpl.ParseAttributes()
    at System.Xml.XmlTextReaderImpl.ParseElement()
    at System.Xml.XmlTextReaderImpl.ParseElementContent()
    at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
    at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
    at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
    at Microsoft.Crm.Platform.Server.Utility.XmlHelper.LoadXmlInfo(String
    xmlInfo)
    at Microsoft.Crm.Query.EntityExpression.ExtractPlatformName(String fetchXml, XElement element).




    Here is the code in questions:





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











    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      This happens when there is &, or other invalid characters in the contract name. My question is, how do I deal with these invalid characters??!!




      Microsoft.Crm.CrmException: Invalid XML. --->
      System.Xml.XmlException: An error occurred while parsing EntityName.
      Line 13, position 117
      .
      at System.Xml.XmlTextReaderImpl.Throw(Exception e)
      at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32&
      charRefEndPos)
      at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
      at System.Xml.XmlTextReaderImpl.ParseAttributes()
      at System.Xml.XmlTextReaderImpl.ParseElement()
      at System.Xml.XmlTextReaderImpl.ParseElementContent()
      at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
      at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
      at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
      at Microsoft.Crm.Platform.Server.Utility.XmlHelper.LoadXmlInfo(String
      xmlInfo)
      at Microsoft.Crm.Query.EntityExpression.ExtractPlatformName(String fetchXml, XElement element).




      Here is the code in questions:





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











      share|improve this question















      This happens when there is &, or other invalid characters in the contract name. My question is, how do I deal with these invalid characters??!!




      Microsoft.Crm.CrmException: Invalid XML. --->
      System.Xml.XmlException: An error occurred while parsing EntityName.
      Line 13, position 117
      .
      at System.Xml.XmlTextReaderImpl.Throw(Exception e)
      at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32&
      charRefEndPos)
      at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
      at System.Xml.XmlTextReaderImpl.ParseAttributes()
      at System.Xml.XmlTextReaderImpl.ParseElement()
      at System.Xml.XmlTextReaderImpl.ParseElementContent()
      at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
      at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
      at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
      at Microsoft.Crm.Platform.Server.Utility.XmlHelper.LoadXmlInfo(String
      xmlInfo)
      at Microsoft.Crm.Query.EntityExpression.ExtractPlatformName(String fetchXml, XElement element).




      Here is the code in questions:





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








      dynamics-crm dynamics-365 fetchxml






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 at 1:08









      jasonscript

      3,51611630




      3,51611630










      asked Nov 11 at 20:45









      Alan Judi

      26011




      26011






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query. I think these are added by the Advanced Find editor; hence the "UI"



          You can rewrite that section of XML like so



          <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>



          Not sure which version of .NET you're using, but you can also use the $ special character to indicate an interpolated string which I think increases readability and reduces string concatenation





          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>";







          share|improve this answer





























            up vote
            0
            down vote













            I used webutility.htmlencode(uiname) and the problem seems to have disappeared. I guess the uiname has some invalid XML characters and this method gets rid of the problem!






            share|improve this answer




















            • uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query; hence the "UI"
              – jasonscript
              Nov 12 at 3:36










            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253064%2finvalid-xml-gt-on-a-plugin-containing-fetchxml%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query. I think these are added by the Advanced Find editor; hence the "UI"



            You can rewrite that section of XML like so



            <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>



            Not sure which version of .NET you're using, but you can also use the $ special character to indicate an interpolated string which I think increases readability and reduces string concatenation





            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>";







            share|improve this answer


























              up vote
              1
              down vote



              accepted










              uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query. I think these are added by the Advanced Find editor; hence the "UI"



              You can rewrite that section of XML like so



              <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>



              Not sure which version of .NET you're using, but you can also use the $ special character to indicate an interpolated string which I think increases readability and reduces string concatenation





              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>";







              share|improve this answer
























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query. I think these are added by the Advanced Find editor; hence the "UI"



                You can rewrite that section of XML like so



                <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>



                Not sure which version of .NET you're using, but you can also use the $ special character to indicate an interpolated string which I think increases readability and reduces string concatenation





                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>";







                share|improve this answer














                uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query. I think these are added by the Advanced Find editor; hence the "UI"



                You can rewrite that section of XML like so



                <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>



                Not sure which version of .NET you're using, but you can also use the $ special character to indicate an interpolated string which I think increases readability and reduces string concatenation





                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>";








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 14 at 1:09

























                answered Nov 12 at 3:49









                jasonscript

                3,51611630




                3,51611630






















                    up vote
                    0
                    down vote













                    I used webutility.htmlencode(uiname) and the problem seems to have disappeared. I guess the uiname has some invalid XML characters and this method gets rid of the problem!






                    share|improve this answer




















                    • uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query; hence the "UI"
                      – jasonscript
                      Nov 12 at 3:36














                    up vote
                    0
                    down vote













                    I used webutility.htmlencode(uiname) and the problem seems to have disappeared. I guess the uiname has some invalid XML characters and this method gets rid of the problem!






                    share|improve this answer




















                    • uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query; hence the "UI"
                      – jasonscript
                      Nov 12 at 3:36












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    I used webutility.htmlencode(uiname) and the problem seems to have disappeared. I guess the uiname has some invalid XML characters and this method gets rid of the problem!






                    share|improve this answer












                    I used webutility.htmlencode(uiname) and the problem seems to have disappeared. I guess the uiname has some invalid XML characters and this method gets rid of the problem!







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 12 at 1:23









                    Alan Judi

                    26011




                    26011











                    • uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query; hence the "UI"
                      – jasonscript
                      Nov 12 at 3:36
















                    • uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query; hence the "UI"
                      – jasonscript
                      Nov 12 at 3:36















                    uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query; hence the "UI"
                    – jasonscript
                    Nov 12 at 3:36




                    uiname and uitype are not required for your fetchXml to work. These are used for presentation and not for the query; hence the "UI"
                    – jasonscript
                    Nov 12 at 3:36

















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253064%2finvalid-xml-gt-on-a-plugin-containing-fetchxml%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                    Museum of Modern and Contemporary Art of Trento and Rovereto