1

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..

1 Answer 1

2

(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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.