Reputation: 1093
using ruby 2, rails 4, gem: xml/mapping
here is the current output:
class Item
include XML::Mapping
array_node :picture_details, 'PictureDetails', :class => PictureURL, :default_value => []
end
class PictureURL
include XML::Mapping
include Initializer
text_node :picture_url, 'PictureURL', :optional => true
end
the output I am getting:
<PictureDetails>
<PictureURL>VALUE</PictureURL>
</PictureDetails>
<PictureDetails>
<PictureURL>VALUE</PictureURL>
</PictureDetails>
<PictureDetails>
<PictureURL>VALUE</PictureURL>
</PictureDetails>
what I want:
<PictureDetails>
<PictureURL>VALUE</PictureURL>
<PictureURL>VALUE</PictureURL>
<PictureURL>VALUE</PictureURL>
</PictureDetails>
I looked over documentation but still can not figure out how I should setup this to reach my desired output..
Upvotes: 1
Views: 259
Reputation: 777
(I'm the author of the xml-mapping gem)
From your description it looks like you want "PictureDetails" to be the base_path of your array node, and "PictureURL" the per-array element path. And in each array element, the PictureURL should just write its picture_url property into the element text, without creating a sub-element or -attribute, which means the path specification of the text_node should be just '.'.
So this should work:
class Item
include XML::Mapping
array_node :picture_details, 'PictureDetails', 'PictureURL', :class => PictureURL, :default_value => []
end
class PictureURL
include XML::Mapping
include Initializer
text_node :picture_url, '.', :optional => true
end
Upvotes: 2