<-- Back

How to resolve document generation errors caused by invalid XML characters while using Document Template

Introduction

This article explains how to resolve the following error when generating a PDF or Rich Text Format (RTF) document using a Document Generation template:

Caused by: com.mendix.modules.microflowengine.MicroflowException:
The character '' is an invalid XML character

This error occurs when an attribute or variable used in the Document Generation template contains hidden or special characters that are not valid in XML.

Document Generation templates convert attribute values and variables into XML before generating the final document. XML supports only a limited set of characters. Control characters in the range 0x00–0x1F, except for tab, newline, and carriage return, are not valid in XML.

Invalid characters are commonly introduced through:

  • Copying and pasting content from Microsoft Word, Microsoft Outlook, Microsoft Teams, or PDF documents
  • Rich-text attributes
  • External data imports
  • Legacy database content

Environment

Studio Pro (all versions)

Instructions/Procedure

The following approaches are commonly used and recommended as workarounds. However, they are not officially supported Mendix features. Use them based on the project’s requirements.

Before sending text values to a Document Generation template, ensure that the content does not include invalid XML characters.

  1. Sanitize data using a Java action or microflow:
    Remove invalid XML characters before sending strings to the template.

  2. Filter data with XSS Sanitize:
    Clean strings using XSS Sanitize before passing them to the template.

  3. Convert symbols to plain text:
    Paste content into a text editor such as VSCode. Non-ASCII characters may appear as boxes or special markers (e.g., a red STX box for '-'). Replace them manually or programmatically.

  4. Manual inspection:
    Inspect content in a plain-text editor to identify unusual or invisible characters and remove them before document generation.

Outcome

PDF or RTF document is generated successfully.

Internal information related

  • 231317, 206782

Additional information

Have more questions? Submit a request

0 Comments

Article is closed for comments.

To provide feedback, please open a ticket here. Don't forget to include the article's URL along with the feedback you would like to provide.