ANS-0411 · PRINTING, PDF & EMAIL TEMPLATES

How to Resolve ‘Error Parsing XML’ in NetSuite Reports and PDFs?

Learn how to prevent common XML parsing errors in NetSuite custom reports and PDF generation by correctly escaping special characters.

Short answer

When encountering an 'Error Parsing XML' message during NetSuite report or PDF generation, it indicates unescaped special characters in your XML data. To resolve this, ensure all string values are properly escaped using the xml.escape(options) function from the N/xml module in SuiteScript 2.1, preventing conflicts with XML syntax.

Scenario

Users may encounter an 'Error Parsing XML' message when attempting to preview or generate custom reports or PDFs in NetSuite. This specific error, 'The entity name must immediately follow the '&' in the entity reference,' typically arises when XML data contains special characters that are not properly escaped, leading to malformed XML.

Solution

To prevent the 'Error Parsing XML' message and ensure proper report or PDF generation, all string values within the XML data must be correctly escaped. This is crucial because unescaped special characters (like '&', '', '"', "'") can be misinterpreted as XML entities or tags, causing parsing failures. In SuiteScript 2.1, the recommended approach is to use the xml.escape(options) function from the N/xml module. Ensure that any string data being incorporated into your XML template is passed through this function before being used. For example:

javascriptvar xmlModule = require('N/xml');var myString = 'Company & Co. <100%';var escapedString = xmlModule.escape({text: myString});// Use escapedString when constructing your XML template

Expert NetSuite Support

Need help with this NetSuite issue?

Printing, PDF & Email Templates consulting and configuration support

Talk to a consultant