Hi All,
We are storing the following data in a text type process variable and mapping it to generate .xml document:-
<Root> <name>ABC</name> <description> <Test Data> "Hello Everyone!" The test isn't done & need further analysis. Refer the file path below: File Path: \\abc\bqpv\¿01. Client File / 729 </description></Root>
We would like to know if there is any out of box feature to handle the characters like & \b <> " ' which is present in the above example inside the tag <description>
Discussion posts and replies are publicly visible
Hi, you can escape the characters
" to " ' to ' < to < > to > & to &
or you can wrap attribute values in double quotes ("), e.g.
<MyTag attr="If a<b & b<c then a<c, it's obvious"/> will resolve into If a<b & b<c then a<c, it's obvious as it can be found easy with google.
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.
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.
You just need a single rule where you can pass in a string and it passes out the "sanitized" version. I'm unclear whether that's what you already have, but this is about as good as you're going to get in Appian.
Thanks for the solution Mike. I have probably done that only. PFB my approach:
Rule "ia_findAndReplaceCharacter" Code is as below:
if( find( ri!search_text, ri!input ) = 0, ri!input, substitute( ri!input, ri!search_text, ri!replace_text ))
Rule "ia_findAndReplaceAllCharacters" Code is as below:
a!localVariables( local!lessThanChar: rule!ia_findAndReplaceCharacter( input: ri!input, search_text: "<", replace_text: "|" ), local!greaterThanChar: rule!ia_findAndReplaceCharacter( input: local!lessThanChar, search_text: ">", replace_text: "|" ), local!apostropheChar: rule!ia_findAndReplaceCharacter( input: local!greaterThanChar, search_text: "'", replace_text: "|" ), local!backspaceChar: rule!ia_findAndReplaceCharacter( input: local!apostropheChar, search_text: "\b", replace_text: "\B" ), local!ampersandChar: rule!ia_findAndReplaceCharacter( input: local!backspaceChar, search_text: "&", replace_text: "and" ), local!finalOutput: local!ampersandChar, local!finalOutput)
Here, we have used rule "ia_findAndReplaceCharacter" for each character.
Is there a way or any function which can find and replace any such special character instead of the above approach.
Thansk Joe for the solution. regexreplaceall() function is a plugin function and also it checks for a specific pattern. Hence, not sure if that will work.
This code replaces all XML special characters in a given XML text.
http://xml.silmaril.ie/specials.html
reduce( substitute(_,_,_), ri!xml, merge( {"&", "<", ">", """", "'"}, {"&", "<", ">", """, "'"} /* Change this to the escape characters listed above.*/ ) )
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()
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.
Thanks Stefan. I would go with your previous solution