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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
actionpack-xml\_parser
======================
A XML parameters parser for Action Pack (removed from core in Rails 4.0)
Installation
------------
Include this gem into your Gemfile:
```ruby
gem 'actionpack-xml_parser'
```
Parameters parsing rules
------------------------
The parameters parsing is handled by `ActiveSupport::XMLConverter` so there may
be specific features and subtle differences depending on the chosen XML backend.
### Hashes
Basically, each node represents a key. With the following XML:
```xml
<person><name>David</name></person>
```
The resulting parameters will be:
```ruby
{"person" => {"name" => "David"}}
```
### File attachment
You can specify the `type` attribute of a node to attach files:
```xml
<person>
<avatar type="file" name="me.jpg" content_type="image/jpg"><!-- File content --></avatar>
</person>
```
The resulting parameters will include a `StringIO` object with the given content,
name and content type set accordingly:
```ruby
{"person" => {"avatar" => #<StringIO:...>}}
```
### Arrays
There are several ways to pass an array. You can either specify multiple nodes
with the same name:
```xml
<person>
<address city="Chicago"/>
<address city="Ottawa"/>
</person>
```
The resulting parameters will be:
```ruby
{"person" => {"address" => [{"city" => "Chicago"}, {"city" => "Ottawa"}]}}
```
You can also specify the `type` attribute of a node and nest child nodes inside:
```xml
<person>
<addresses type="array">
<address city="Melbourne"/>
<address city="Paris"/>
</addresses>
</person>
```
will result in:
```ruby
{"person" => {"addresses" => [{"city" => "Melbourne"}, {"city" => "Paris"}]}}
```
|