# Unexpected results from roundtrip through ActiveResource to\_xml/from\_xml - string isn't the same?

**URL:** <https://www.ruby-forum.com/t/unexpected-results-from-roundtrip-through-activeresource-to-xml-from-xml-string-isnt-the-same/117324>\
**Category:** Rails\
**Created:** [October 16, 2007, 12:00am UTC](https://www.ruby-forum.com/t/unexpected-results-from-roundtrip-through-activeresource-to-xml-from-xml-string-isnt-the-same/117324 "2007-10-16T00:00:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![noagenda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8c91f0/32.png) [@noagenda](https://www.ruby-forum.com/u/noagenda)\
**Post date:** [October 16, 2007, 12:00am UTC](https://www.ruby-forum.com/t/unexpected-results-from-roundtrip-through-activeresource-to-xml-from-xml-string-isnt-the-same/117324/1 "2007-10-16T00:00:41Z")

</div>

I’m trying to figure out why I get a different string after a  
round-trip through to\_xml/from\_xml. I’m using edge rails, rev is  
7921, and I see the same results on Windows and Linux.

Here’s the code:

require File.dirname( **FILE** ) + ‘/…/config/boot’  
require RAILS\_ROOT + ‘/config/environment’

class Foo \< ActiveResource::Base  
self.site = “[http://localhost](http://localhost)”  
end

f = Foo.new(:x =\> “\304”)  
puts f.to\_xml  
results = Hash.from\_xml(f.to\_xml)  
puts results.inspect  
puts "Value for character in original: #{f.x[0]}; "  
puts “Value for character after round-trip through xml:  
#{results[‘foo’][‘x’][0]}”

And here’s the result:

\<?xml version="1.0" encoding="UTF-8"?\> Ä {"foo"=\>{"x"=\>"Ä"}} Value for character in original: 196; Value for character after round-trip through xml: 195

Shouldn’t that last 195 be 196?

–  
James M. | removed\_email\_address@domain.invalid  
Ruby and Ruby on Rails consulting  
[blog.restphone.com](http://blog.restphone.com)
