tags:

views:

4902

answers:

9

I am using xsl to control the output of my xml file, but the BOM character is being added.

Thanks

+1  A: 

Just strip first two bytes using any hex editor.

Dev er dev
Or 3, depending on UTF flavor
MSalters
Or 4, for UTF-32. But it's most likely 3, UTF-8 being the most common encoding for XML.
Alan Moore
+1  A: 

The BOM character is whitespace (non-breaking and zero-width) outside any tag. That should make it irrelevant. Can you clarify why it's a problem for you?

MSalters
+1  A: 

Unlike on plain text files, a byte order mark on a XML file should never cause any problems, since all XML parsers should be able to deal with it, even if it is the "UTF-8 BOM". In fact, it is even suggested on the XML standard itself as part of character encoding autodetection.

CesarB
This is not a suggestion, section F is not normative. A UTF-8 BOM is explicitly allowed by the Unicode standard, but is not recommended - http://en.wikipedia.org/wiki/Byte_order_mark#cite_note-2 - the UTF-8 BOM does not indicate byte order.
mjustin
A: 

I was under the impression that XML is encouraged to be written in Unicode, in some Unicode encoding, and that certain Unicode encodings are specified to contain an initial byte-order mark. Without that byte-order mark, your file is no longer correctly encoded in a Unicode encoding and therefore no longer correct XML. XML processors are encouraged to be unforgiving, to fail immediately on the slightest error (such as an incorrect Unicode encoding). What kinds of XML processors are you looking to break?

Obviously, stripping a byte-order mark from a UTF-8 encoded document makes that document appear to be ASCII encoded (not Unicode), and some text processors are capable only of using ASCII encoded documents. Is this what you're working with?

Justice
For XML files which do not specify the encoding and have no BOM, UTF-8 is the default encoding.
mjustin
A: 

Thanks guys for all your responses. I have just requested more information from the client as to why the xml file is breaking (its for a data feed). From our stand point the xml is valid but apparently they are using some xml validation tool we haven't access to. But when I get feedback from them, I'll let you guys know.

Thanks once again y'all.

+1  A: 

I've had this happen to me,and here's how I solved it (link to another SO question).

George Stocker
A: 

What output encoding is your XSL set to use? What encoding is the input document? Where's the input coming from, and where was it saved/uploaded/dowloaded in the meantime?

XML and XSL should default to using UTF-8 if nothing else is specified. But clearly, something's going wrong here.

One thing which might happen is, the XML is being served up by a web server which is set by default to serve in ISO-8859-1, a pretty good default ... pre-Unicode.

Slightly off-topic, but Joel's very instructive article about text encodings was an eye-opener to me. There are a lot of people out there who are otherwise very smart about programming, but who persist in thinking there's such a thing as "plain text" or calling their text "ASCII" or "ANSI". It's an issue you really need to get to grips with if you haven't yet.

AmbroseChapel
+9  A: 
# vim file.xml
:set nobomb
:wq
bene
A: 

The File BOM Detector (freeware for Windows) makes it easy to remove the byte order mark.

Anthony Faull