0

I'm trying to generate a simple XML feed using Rails' to_xml:

xml = {
  :id    => '1234',
  :title => 'Title',
  :url   => 'www.site.com',
  :items => items.to_xml(:skip_instruct => true, :skip_types => true, :include => :user)
}.to_xml(:root => 'feed', :skip_types => true)

I have two problems with this approach:

  1. Everything inside <items> is ecscaped and renders as regular text.
  2. It generates an additional <items> node

So the resulting <items> node looks like

<items>
 &lt;items&gt; ... &lt;/items&gt;
<items>

How can I make it work using just to_xml?

1 Answer 1

1

You should be able to use this syntax:

xml = {
  :id    => '1234',
  :title => 'Title',
  :url   => 'www.site.com',
  :items => items 
}.to_xml(:root => 'feed', :skip_types => true)

Any options you apply to the whole transformation should(?) apply to the items transformation.

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.