Hi,
It looks like element names are serialized in a case-insensitive way if the element is added as a string to a document that declares a different encoding:
# encoding: utf-8
f = <<-EOT
<?xml version="1.0" encoding="us-ascii"?>
<root>
<p>foo</p>
</root>
EOT
r = Nokogiri.XML(f)
p = r.at_css('p').replace('<yYy>©bar</yYy>')
puts r.to_s
This produces:
<?xml version="1.0" encoding="us-ascii"?>
<root>
<yyy>©bar</yyy>
</root>
I tested this on nokogiri 1.6.3.1, libxml2 2.8.0. Is this a libxml2 problem, maybe?