I'm using XML(xslt) - How to fix the BOM issue

Darius used Ask the Experts™
Hi Guys,

I am using xslt(mapping) to create output xml file.
Issue: target system compline about added BOM character.

These outputs configurations does not fix an issue
<xsl:output method="xml" version="1.0" encoding="utf-8" omit-xml-declaration="no" indent="yes"/>
 <xsl:output method="xml" version="1.0" encoding="ASCII" omit-xml-declaration="no" indent="yes"/>

Open in new window

I'm using online validator to test output xml file

Any advice?

Thank you!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Gertone (Geert Bormans)Information Architect
Top Expert 2006
First let me say this: a BOM should not at all make difference on an XML file. And XML processing application that claims to validate or handle XML correctly should know how to handle the BOM. So if the BOM is causing issues with th ereceiving end, the receiving end is NOT a decent XML processor at all (I am raising this as a warning, other issues will pop up later if you have bypassed the BOM issue)

It is not the XSLT processor that ads the BOM. THat is the serialisation process and it is pretty hard to correct that from within the XSLT.
So every advice you can find if you google this issue that says that you need to change the xsl:output or the output encoding is only right in a VERY limited context

So, bottom line is "how do you serialise?"
This question can only be answered outside a limited context if we know
- what XSLT processor you use
- how you execute the XSLT
- .... anything that can help us understand the details of your transformation


We created an internal transformer service in C# that uses the class XslTransformer.
Information Architect
Top Expert 2006
OK, basically that ignores the xsl:output completely
If you are using a XML writer

XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Encoding = new UTF8Encoding(false);

this way you set the encoding to UTF8 and will not create the BOM
Most Valuable Expert 2011
Top Expert 2016

Some of this information might be helpful, too.  I found that some common text editors will add a BOM, whether you want it or not.

See BOM is Decidedly Not Da Bomb in this article:
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Thanks for the article reference Ray. Have just scanned through it but it definitely deserves some in detail reading later.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial