-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
63 lines (48 loc) · 1.56 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
UnopinionatedHashFromXml
=====================================================================
Installation:
./script/plugin install git://github.com/skinandbones/unopinionated_hash_from_xml.git
Usage:
Hash.from_xml(xml, :unrename_keys => false)
Description:
Adds an option to Hash#from_xml to allow you to bypass automatic hash
key "unrenaming". As of Rails 2.3, Hash#from_xml will sanitize the
XML node names when it creates the keys for the newly formed hash.
For example, an XML node with the name "fontName" will have the key
"font_name" in the resulting hash.
This plugin adds an optional parameter to Hash#from_xml to get the
pre-Rails 2.3 behavior where keys are not renamed.
Example:
>> xml = <<-END
<doc>
<titleSize>20</titleSize>
<bodySize>10</bodySize>
<footer-size>10</footer-size>
<title>Stuff</title>
<TopLevel>
<middle-level-one>
<bottom>1</bottom>
</middle-level-one>
<middleLevelTwo>
<Bottom>2</Bottom>
</middleLevelTwo>
</TopLevel>
</doc>
END
>> pp Hash.from_xml(xml)
{"doc"=>
{"body_size"=>"10",
"title"=>"Stuff",
"title_size"=>"20",
"top_level"=>
{"middle_level_two"=>{"bottom"=>"2"}, "middle_level_one"=>{"bottom"=>"1"}},
"footer_size"=>"10"}}
>> pp Hash.from_xml(xml, :unrename_keys => false)
{"doc"=>
{"footer-size"=>"10",
"title"=>"Stuff",
"titleSize"=>"20",
"bodySize"=>"10",
"TopLevel"=>
{"middleLevelTwo"=>{"Bottom"=>"2"}, "middle-level-one"=>{"bottom"=>"1"}}}}
Copyright (c) 2009 Blake Carlson, released under the MIT license