<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to handle special character in XML document</title><link>https://community.appian.com/discussions/f/general/20024/how-to-handle-special-character-in-xml-document</link><description>Hi All, 
 We are storing the following data in a text type process variable and mapping it to generate .xml document:- 
 &amp;lt;Root&amp;gt; &amp;lt;name&amp;gt;ABC&amp;lt;/name&amp;gt; &amp;lt;description&amp;gt; &amp;lt;Test Data&amp;gt; &amp;quot;Hello Everyone!&amp;quot; The test isn&amp;#39;t done &amp;amp; need further analysis. Refer the file path</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to handle special character in XML document</title><link>https://community.appian.com/thread/78324?ContentTypeID=1</link><pubDate>Mon, 07 Dec 2020 13:49:18 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:709518ab-b963-48cc-987a-a1f0a46f3a44</guid><dc:creator>anushrid0001</dc:creator><description>&lt;p&gt;Thanks Stefan. I would go with your previous solution&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle special character in XML document</title><link>https://community.appian.com/thread/78316?ContentTypeID=1</link><pubDate>Mon, 07 Dec 2020 08:49:30 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:75833263-395b-4184-9fc7-f8184cedd779</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;There is no ready made function available. You know the function toXml()? It has some quirks, but would take care of all you escape needs.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle special character in XML document</title><link>https://community.appian.com/thread/78315?ContentTypeID=1</link><pubDate>Mon, 07 Dec 2020 07:49:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e02cb5af-9ca6-4eaf-a609-a993afbf1980</guid><dc:creator>anushrid0001</dc:creator><description>&lt;p&gt;Thanks Stefan for the solution. However, I would like to know if we can encode special characters in Appian in the similar manner which can be done in other programming language with functions like encode()&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle special character in XML document</title><link>https://community.appian.com/thread/78314?ContentTypeID=1</link><pubDate>Mon, 07 Dec 2020 07:31:20 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:136d77cf-046a-4322-8b87-f8dae2830459</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;This code replaces all XML special characters in a given XML text.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://xml.silmaril.ie/specials.html"&gt;http://xml.silmaril.ie/specials.html&lt;/a&gt;&lt;/p&gt;
&lt;pre class="default s-code-block hljs xml"&gt;&lt;code&gt;&amp;quot; to  &lt;span class="hljs-symbol"&gt;&amp;amp;quot;&lt;/span&gt;
&amp;#39; to  &lt;span class="hljs-symbol"&gt;&amp;amp;apos;&lt;/span&gt;
&lt;span class="hljs-tag"&gt;&amp;lt; &lt;span class="hljs-attr"&gt;to&lt;/span&gt;  &amp;amp;&lt;span class="hljs-attr"&gt;lt&lt;/span&gt;;
&amp;gt;&lt;/span&gt; to  &lt;span class="hljs-symbol"&gt;&amp;amp;gt;&lt;/span&gt;
&amp;amp; to  &lt;span class="hljs-symbol"&gt;&amp;amp;amp;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;reduce(
  substitute(_,_,_),
  ri!xml,
  merge(
    {&amp;quot;&amp;amp;&amp;quot;, &amp;quot;&amp;lt;&amp;quot;, &amp;quot;&amp;gt;&amp;quot;, &amp;quot;&amp;quot;&amp;quot;&amp;quot;, &amp;quot;&amp;#39;&amp;quot;},
    {&amp;quot;&amp;amp;&amp;quot;, &amp;quot;&amp;lt;&amp;quot;, &amp;quot;&amp;gt;&amp;quot;, &amp;quot;&amp;quot;&amp;quot;, &amp;quot;&amp;#39;&amp;quot;} /* Change this to the escape characters listed above.*/
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle special character in XML document</title><link>https://community.appian.com/thread/78313?ContentTypeID=1</link><pubDate>Mon, 07 Dec 2020 06:39:27 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:472ff8ae-2d02-43b6-bcf0-989ba559e0bc</guid><dc:creator>anushrid0001</dc:creator><description>&lt;p&gt;Thansk Joe for the solution. r&lt;span&gt;egexreplaceall() function is a plugin function and also it checks for a specific pattern. Hence, not sure if that will work.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle special character in XML document</title><link>https://community.appian.com/thread/78312?ContentTypeID=1</link><pubDate>Mon, 07 Dec 2020 06:37:46 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e81d465d-e9c9-41b4-b52d-0fa4300df8e3</guid><dc:creator>anushrid0001</dc:creator><description>&lt;p&gt;Thanks for the solution Mike. I have probably done that only. PFB my approach:&lt;/p&gt;
&lt;p&gt;Rule &amp;quot;ia_findAndReplaceCharacter&amp;quot; Code is as below:&lt;/p&gt;
&lt;p&gt;if(&lt;br /&gt; find(&lt;br /&gt; ri!search_text,&lt;br /&gt; ri!input&lt;br /&gt; ) = 0,&lt;br /&gt; ri!input,&lt;br /&gt; substitute(&lt;br /&gt; ri!input,&lt;br /&gt; ri!search_text,&lt;br /&gt; ri!replace_text&lt;br /&gt; )&lt;br /&gt;)&lt;/p&gt;
&lt;p&gt;Rule&amp;nbsp;&amp;quot;ia_findAndReplaceAllCharacters&amp;quot; Code is as below:&lt;/p&gt;
&lt;p&gt;a!localVariables(&lt;br /&gt; local!lessThanChar: rule!ia_findAndReplaceCharacter(&lt;br /&gt; input: ri!input,&lt;br /&gt; search_text: &amp;quot;&amp;lt;&amp;quot;,&lt;br /&gt; replace_text: &amp;quot;|&amp;quot;&lt;br /&gt; ),&lt;br /&gt; local!greaterThanChar: rule!ia_findAndReplaceCharacter(&lt;br /&gt; input: local!lessThanChar,&lt;br /&gt; search_text: &amp;quot;&amp;gt;&amp;quot;,&lt;br /&gt; replace_text: &amp;quot;|&amp;quot;&lt;br /&gt; ),&lt;br /&gt; local!apostropheChar: rule!ia_findAndReplaceCharacter(&lt;br /&gt; input: local!greaterThanChar,&lt;br /&gt; search_text: &amp;quot;&amp;#39;&amp;quot;,&lt;br /&gt; replace_text: &amp;quot;|&amp;quot;&lt;br /&gt; ),&lt;br /&gt; local!backspaceChar: rule!ia_findAndReplaceCharacter(&lt;br /&gt; input: local!apostropheChar,&lt;br /&gt; search_text: &amp;quot;\b&amp;quot;,&lt;br /&gt; replace_text: &amp;quot;\B&amp;quot;&lt;br /&gt; ),&lt;br /&gt; local!ampersandChar: rule!ia_findAndReplaceCharacter(&lt;br /&gt; input: local!backspaceChar,&lt;br /&gt; search_text: &amp;quot;&amp;amp;&amp;quot;,&lt;br /&gt; replace_text: &amp;quot;and&amp;quot;&lt;br /&gt; ),&lt;br /&gt; local!finalOutput: local!ampersandChar,&lt;br /&gt; local!finalOutput&lt;br /&gt;)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here, we have used rule&amp;nbsp; &amp;quot;&lt;span&gt;ia_findAndReplaceCharacter&amp;quot; for each character.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Is there a way or any function which can find and replace any such special character instead of the above approach.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle special character in XML document</title><link>https://community.appian.com/thread/78299?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2020 15:40:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:02f08937-80f7-49bd-99e1-893e46163ead</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;You just need a single rule where you can pass in a string and it passes out the &amp;quot;sanitized&amp;quot; version.&amp;nbsp; I&amp;#39;m unclear whether that&amp;#39;s what you already have, but this is about as good as you&amp;#39;re going to get in Appian.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle special character in XML document</title><link>https://community.appian.com/thread/78297?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2020 14:10:43 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:dfc0348d-f732-413e-a4d2-41187d0127d1</guid><dc:creator>anushrid0001</dc:creator><description>&lt;p&gt;Thanks for the response. We have created a common rule to find the character and replace it with the required character individually. Hence, the same rule will check the characters individually. However, is there a way to check and all special characters at once and replace with the respective required characters.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle special character in XML document</title><link>https://community.appian.com/thread/78296?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2020 13:35:58 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d4c2c842-6800-47de-b877-5b64260c1fb8</guid><dc:creator>Joe</dc:creator><description>&lt;p&gt;Not sure if this helps..If we encounter odd/special characters from copy/paste text, executing a Regexreplaceall() function to strip illegal or unwanted characters can be useful.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle special character in XML document</title><link>https://community.appian.com/thread/78295?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2020 13:34:17 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3ca12e40-2df0-4006-8b76-25453afe83c5</guid><dc:creator>juergeng393</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;br /&gt;you can escape the characters&lt;/p&gt;
&lt;pre class="default s-code-block hljs xml"&gt;&lt;code&gt;&amp;quot; to  &lt;span class="hljs-symbol"&gt;&amp;amp;quot;&lt;/span&gt;
&amp;#39; to  &lt;span class="hljs-symbol"&gt;&amp;amp;apos;&lt;/span&gt;
&lt;span class="hljs-tag"&gt;&amp;lt; &lt;span class="hljs-attr"&gt;to&lt;/span&gt;  &amp;amp;&lt;span class="hljs-attr"&gt;lt&lt;/span&gt;;
&amp;gt;&lt;/span&gt; to  &lt;span class="hljs-symbol"&gt;&amp;amp;gt;&lt;/span&gt;
&amp;amp; to  &lt;span class="hljs-symbol"&gt;&amp;amp;amp;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class="default s-code-block hljs xml"&gt;&lt;code&gt;&lt;span class="hljs-symbol"&gt;or you can &lt;span&gt;wrap attribute values in double quotes (&lt;/span&gt;&amp;quot;&lt;span&gt;), e.g.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class="default s-code-block hljs xml"&gt;&lt;code&gt;&lt;span class="hljs-tag"&gt;&amp;lt;&lt;span class="hljs-name"&gt;MyTag&lt;/span&gt; &lt;span class="hljs-attr"&gt;attr&lt;/span&gt;=&lt;span class="hljs-string"&gt;&amp;quot;If a&lt;span class="hljs-symbol"&gt;&amp;amp;lt;&lt;/span&gt;b &lt;span class="hljs-symbol"&gt;&amp;amp;amp;&lt;/span&gt; b&lt;span class="hljs-symbol"&gt;&amp;amp;lt;&lt;/span&gt;c then a&lt;span class="hljs-symbol"&gt;&amp;amp;lt;&lt;/span&gt;c, it&amp;#39;s obvious&amp;quot;&lt;/span&gt;/&amp;gt; will resolve into
&lt;span&gt;If a&amp;lt;b &amp;amp; b&amp;lt;c then a&amp;lt;c, it&amp;#39;s obvious as it can be found easy with google.&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class="default s-code-block hljs xml"&gt;&lt;code&gt;&lt;span class="hljs-symbol"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>