I’m having trouble using Hash.from_xml, so I dropped into script/
console to see what was happening.
<?xml version="1.0" encoding="UTF-8"?> 0t = Trackable.find(1)
=> #<Activity:0xb707e5b0 @attributes={“visibility”=>“0”, “code”=>“K”,
“type”=>“Activity”, “disposition”=>“2”, “id”=>“1”,
“description”=>“Kahu”, “owner_id”=>“3”, “projected_completed_at”=>nil,
“parent_id”=>nil, “created_at”=>“2007-08-17 19:19:27”}>a = t.attributes
=> {“visibility”=>0, “code”=>“K”, “type”=>“Activity”, “id”=>1,
“disposition”=>2, “description”=>“Kahu”,
“projected_completed_at”=>nil, “owner_id”=>3, “parent_id”=>nil,
“created_at”=>Fri Aug 17 19:19:27 UTC 2007}a.to_xml
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n <visibility
type=“integer”>0\nK
\n Activity</
type>\n <id type=“integer”>1\n <disposition type="integer
“>2\n Kahu\n <projected-
completed-at nil=“true”>\n <owner-id type=
“integer”>3\n <parent-id nil=“true”>\n
<created-at type=“datetime”>2007-08-17T19:19:27Z\n</
hash>\n”puts a.to_xml
K
Activity
1
2
Kahu
3
2007-08-17T19:19:27Z
=> nil
>> Hash.from_xml(a.to_xml)
=> {"hash"=>nil}
That doesn’t work, but this does:
<?xml version="1.0" encoding="UTF-8"?> 1 2 => nil >> Hash.from_xml(h.to_xml) => {"hash"=>{"a"=>"1", "b"=>"2"}}h = {‘a’ => ‘1’, ‘b’ => ‘2’}
=> {“a”=>“1”, “b”=>“2”}h.to_xml
=> “<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n 1\n
2\n\n”puts h.to_xml
I’m using Rails 1.2.3.
Am I doing anything wrong, or is from_xml not working properly?
Ryan