# Libxml utf-8 locale

**URL:** <https://www.ruby-forum.com/t/libxml-utf-8-locale/78015>\
**Category:** Ruby\
**Created:** [March 7, 2006, 8:46pm UTC](https://www.ruby-forum.com/t/libxml-utf-8-locale/78015 "2006-03-07T20:46:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@Mage](https://www.ruby-forum.com/u/Mage)\
**Post date:** [March 7, 2006, 8:46pm UTC](https://www.ruby-forum.com/t/libxml-utf-8-locale/78015/1 "2006-03-07T20:46:29Z")

</div>

Hello,

honestly if I was to select two things I hate about computers, they  
should be XML and UTF-8.

I have an xml file:

“\<?xml version='1.0' encoding='UTF-8'?\>…”

I have installed libxml-ruby and liblocale-ruby on my etch debian.

I have tried:  
export LANG=hu\_HU.UTF-8  
kate sample.xml  
it opens the file correctly.

I have tried  
export LANG=hu\_HU.UTF-8  
my\_script.rb sample.xml

It cannot deal with the UTF chars. I also have tried insert this line  
into my script (with require ‘locale’ of course):  
Locale.setlocale(Locale::LC\_ALL, ‘hu\_HU.UTF-8’)

No effect.

My script is similar to the one in the docs:

```
    require 'xml/libxml'
    doc = XML::Document.file('output.xml')
    root = doc.root

    puts "Root element name: #{root.name}"

    elem3 = root.find('elem3').to_a.first
    puts "Elem3: #{elem3['attr']}"

    doc.find('//root_node/foo/bar').each do |node|
      puts "Node path: #{node.path} \t Contents: #{node}"
    end

```

(I am not using this but something like that with setlocale.)

The output is filled with:  
KÃ?Â­nÃ?Â¡l

What to do now?

Mage

---

<div class="post-metadata">

**Author:** ![Mage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@Mage](https://www.ruby-forum.com/u/Mage)\
**Post date:** [March 7, 2006, 9:54pm UTC](https://www.ruby-forum.com/t/libxml-utf-8-locale/78015/2 "2006-03-07T21:54:12Z")

</div>

On Mar 7, 2006, at 2:43 PM, Mage wrote:

> line into my script (with require ‘locale’ of course):  
> puts “Root element name: #{root.name}”
> 
> The output is filled with:  
> KÃ nÃ¡l
> 
> What to do now?
> 
> Mage

Have you tried putting  
$KCODE=u  
at the top of your script? (possibly before any requires.)

---

<div class="post-metadata">

**Author:** ![Mage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@Mage](https://www.ruby-forum.com/u/Mage)\
**Post date:** [March 8, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/libxml-utf-8-locale/78015/3 "2006-03-08T18:10:13Z")

</div>

Logan C. wrote:

> > “\<?xml version='1.0' encoding='UTF-8'?\>…”  
> > my\_script.rb sample.xml  
> > doc = XML::Document.file(‘output.xml’)
> 
> Have you tried putting  
> $KCODE=u  
> at the top of your script? (possibly before any requires.)

Didn’t help.

Now I am using iconv converter for some nodes, but I think it’s a nasty  
way.

Mage
