How to Eliminate Invalid XML Characters
Ensure results pass successfully between nodes by making sure your XML characters are valid.
When passing results between nodes, you need valid XML. Here's how to make sure you only pass valid XML characters.
When the Task Engine processes XML that is passed to it as a string. If the XML you are passing includes @values value that could possibly include invalid XML characters, you (the Task Tree creator) are responsible for making sure it is valid.
If you are only passing list style answers to your XML strings this isn't normally an issue - you control the content. If you are passing answers from Free Text questions, you could easily have invalid content.
Here are the invalid character that can not be included in XML content: &
, <
, >
Here are the valid replacements &
, >
, <
Since you can perform Ruby functions in a node parameter, the easiest way to remove invalid character is with gsub. The invalid character need to be replaces with valid substitutions.
The Task Engine can work with the replaced value, and will "translate" it back to the correct value when passing parameters. For example, you create the result to pass back to a deferred node, and then use that result to set a field in a Remedy form.
The result must be valid XML, because the result is just a string that is formatted XML. When passing the processed result to a Remedy field, the task engine knows that is is a replaced value for XML and will translate back to the original value.
Here is an example of using the gsub function on a Free Text question called "Summary"
@answer['Summary'].gsub('&', '&').gsub('>', '>').gsub('<', '<')
Updated over 1 year ago