# Utf-16 little endian byte order mark with libxml-ruby

**URL:** <https://www.ruby-forum.com/t/utf-16-little-endian-byte-order-mark-with-libxml-ruby/110325>\
**Category:** Ruby\
**Created:** [July 25, 2007, 11:25am UTC](https://www.ruby-forum.com/t/utf-16-little-endian-byte-order-mark-with-libxml-ruby/110325 "2007-07-25T11:25:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [July 25, 2007, 11:25am UTC](https://www.ruby-forum.com/t/utf-16-little-endian-byte-order-mark-with-libxml-ruby/110325/1 "2007-07-25T11:25:00Z")

</div>

Hey all

I am producting an xml file for which is destined to be used by another  
application, and after some investigation I have found that there parser  
always looks for a BOM at the begining of a file, indicating that the  
encoding is UTF-16.

When I call @document.encoding = ‘utf-16’ on my xml document it does  
appear to attach the BOM to the begining of the file, but then doesnt  
output the rest of the xml?! If I change back to utf-8 everything works  
perfectly fine. Has anyone done any utf-16 parsing/creation with libxml  
before?

The characters used as the BOM are “Ã¿Ã¾” (\<Latin small letter y with  
diaeresis, Latin small letter thorn\>, \<U+00FF U+00FE\>).

Any help would be great

Cheers

Tim

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [July 25, 2007, 2:50pm UTC](https://www.ruby-forum.com/t/utf-16-little-endian-byte-order-mark-with-libxml-ruby/110325/2 "2007-07-25T14:50:11Z")

</div>

It appears that the save() method on XML::Document will create files if  
none exsist and add the bom for you 🙂 brilliant!!

- Tim
