SlideShare a Scribd company logo
Using REST and XML Builder for
legacy XML
Keith Pitty
http://keithpitty.com
REST is great for responding to different formats
class NewsItemsController < ApplicationController

  def index
    @news_items = NewsItem.all

    respond_to do |format|
      format.html # index.rhtml
      format.xml { render :xml => @news_items.to_xml }
    end
  end

  def show
    @news_item = NewsItem.find(params[:id])

    respond_to do |format|
      format.html # show.rhtml
      format.xml { render :xml => @news_item.to_xml }
    end
  end
end
@news_items.to_xml
# == Schema Information
#
# Table name: news_items
#
# id          :integer(4)     not null, primary key
# heading     :string(255)
# author      :string(255)
# body        :text
# created_at :datetime
# updated_at :datetime
#

class NewsItem < ActiveRecord::Base
end
So it’s easy to provide XML via to_xml, right?
But what if a legacy XML format is imposed?
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
<newsletter>
  <summary>
    <title>The Trinity Tribune</title>
    <date>June 9th, 2009</date>
  </summary>
  <feature>
    <article heading=quot;Railscamp 5 a Roaring Successquot; by=quot;Lachie Coxquot;>
      Railscamp 5 started out so well. Saturday was awesome...
    </article>
  </feature>
  <article heading=quot;Bivou.ac blows Heroku away!quot; by=quot;Martin Stannardquot;>
    Move over Heroku, bivou.ac is here!
  </article>
  <article heading=quot;Bananas de jourquot; by=quot;Tim Lucasquot;>
    Bon jour, campers! Wanna share some cool code?
  </article>
</newsletter>
Use presenter object and Builder::XmlBuilder
class NewsletterController < ApplicationController

  def show
    @newsletter = Newsletter.new
    respond_to do |format|
      format.xml { render :action => quot;show.xml.builderquot;,
                           :layout => false }
    end
  end

end
remember the legacy xml format?
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
<newsletter>
  <summary>
    <title>The Trinity Tribune</title>
    <date>June 9th, 2009</date>
  </summary>
  <feature>
    <article heading=quot;Railscamp 5 a Roaring Successquot; by=quot;Lachie Coxquot;>
      Railscamp 5 started out so well. Saturday was awesome...
    </article>
  </feature>
  <article heading=quot;Bivou.ac blows Heroku away!quot; by=quot;Martin Stannardquot;>
    Move over Heroku, bivou.ac is here!
  </article>
  <article heading=quot;Bananas de jourquot; by=quot;Tim Lucasquot;>
    Bon jour, campers! Wanna share some cool code?
  </article>
</newsletter>
app/views/newsletters/show.xml.builder

     contains Builder::XmlMarkup
xml.instruct!
xml.newsletter {
  xml.summary {
    xml.title quot;The Trinity Tribunequot;
    xml.date quot;#{Date.today.to_formatted_s(:rfc822)}quot;
  }
  xml.feature {
    @newsletter.feature_article(quot;headingquot; => feature_article.heading,
                                 quot;byquot; => feature_article.author)
  }
  @newsletter.articles.each { |article|
    xml.article(quot;headingquot; => article.heading,
                 quot;byquot; => article.author)
  }
}
Presenter class
class Newsletter
  attr_reader :articles, :feature_article

  def initialize
    @articles = NewsItem.all_except_for_feature
  end

  def feature_article
    @feature_article = NewsItem.feature
  end

  # Potential for more useful methods here

end
this example is simple and contrived
hopefully you can imagine how this technique
 could be useful in more complex examples
Summary


REST needs a bit of help sometimes
XML Builder useful for producing XML in legacy format
Presenter object can help encapsulate what is required in the XML
markup

More Related Content

Similar to Using REST and XML Builder for legacy XML

Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18HUST
 
AD215 - Practical Magic with DXL
AD215 - Practical Magic with DXLAD215 - Practical Magic with DXL
AD215 - Practical Magic with DXLStephan H. Wissel
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handlingSuite Solutions
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2borkweb
 
Tugas Pw [6]
Tugas Pw [6]Tugas Pw [6]
Tugas Pw [6]guestca37172
 
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To AskEverything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To AskRichard Davis
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous MerbMatt Todd
 
Struts2
Struts2Struts2
Struts2yuvalb
 
Well
WellWell
Wellbreccan
 
Ajax
AjaxAjax
Ajaxwangjiaz
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSFSoftServe
 
Flex With Rubyamf
Flex With RubyamfFlex With Rubyamf
Flex With RubyamfTony Hillerson
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amfrailsconf
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
Ajax Applications with RichFaces and JSF 2
Ajax Applications with RichFaces and JSF 2Ajax Applications with RichFaces and JSF 2
Ajax Applications with RichFaces and JSF 2Max Katz
 
How To Flex - Fondamentali
How To Flex - FondamentaliHow To Flex - Fondamentali
How To Flex - FondamentaliFrancesco Bramato
 

Similar to Using REST and XML Builder for legacy XML (20)

Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18
 
AD215 - Practical Magic with DXL
AD215 - Practical Magic with DXLAD215 - Practical Magic with DXL
AD215 - Practical Magic with DXL
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 
JavaScript
JavaScriptJavaScript
JavaScript
 
EPiServer Web Parts
EPiServer Web PartsEPiServer Web Parts
EPiServer Web Parts
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 
Tugas Pw [6]
Tugas Pw [6]Tugas Pw [6]
Tugas Pw [6]
 
Tugas Pw [6] (2)
Tugas Pw [6] (2)Tugas Pw [6] (2)
Tugas Pw [6] (2)
 
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To AskEverything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To Ask
 
Jsp
JspJsp
Jsp
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
 
Struts2
Struts2Struts2
Struts2
 
Well
WellWell
Well
 
Ajax
AjaxAjax
Ajax
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSF
 
Flex With Rubyamf
Flex With RubyamfFlex With Rubyamf
Flex With Rubyamf
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Ajax Applications with RichFaces and JSF 2
Ajax Applications with RichFaces and JSF 2Ajax Applications with RichFaces and JSF 2
Ajax Applications with RichFaces and JSF 2
 
How To Flex - Fondamentali
How To Flex - FondamentaliHow To Flex - Fondamentali
How To Flex - Fondamentali
 

More from Keith Pitty

The Only Way to Test!
The Only Way to Test!The Only Way to Test!
The Only Way to Test!Keith Pitty
 
Ruby Australia
Ruby AustraliaRuby Australia
Ruby AustraliaKeith Pitty
 
RVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby TrackerRVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby TrackerKeith Pitty
 
Happy Hacking
Happy HackingHappy Hacking
Happy HackingKeith Pitty
 
Automated Testing with Ruby
Automated Testing with RubyAutomated Testing with Ruby
Automated Testing with RubyKeith Pitty
 
What\'s new in Rails 2.1
What\'s new in Rails 2.1What\'s new in Rails 2.1
What\'s new in Rails 2.1Keith Pitty
 
Why would a Java shop want to use Ruby?
Why would a Java shop want to use Ruby?Why would a Java shop want to use Ruby?
Why would a Java shop want to use Ruby?Keith Pitty
 

More from Keith Pitty (7)

The Only Way to Test!
The Only Way to Test!The Only Way to Test!
The Only Way to Test!
 
Ruby Australia
Ruby AustraliaRuby Australia
Ruby Australia
 
RVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby TrackerRVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby Tracker
 
Happy Hacking
Happy HackingHappy Hacking
Happy Hacking
 
Automated Testing with Ruby
Automated Testing with RubyAutomated Testing with Ruby
Automated Testing with Ruby
 
What\'s new in Rails 2.1
What\'s new in Rails 2.1What\'s new in Rails 2.1
What\'s new in Rails 2.1
 
Why would a Java shop want to use Ruby?
Why would a Java shop want to use Ruby?Why would a Java shop want to use Ruby?
Why would a Java shop want to use Ruby?
 

Recently uploaded

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...Product School
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCzechDreamin
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeCzechDreamin
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Product School
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...Elena Simperl
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationZilliz
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 

Recently uploaded (20)

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 

Using REST and XML Builder for legacy XML

  • 1. Using REST and XML Builder for legacy XML Keith Pitty http://keithpitty.com
  • 2. REST is great for responding to different formats
  • 3. class NewsItemsController < ApplicationController def index @news_items = NewsItem.all respond_to do |format| format.html # index.rhtml format.xml { render :xml => @news_items.to_xml } end end def show @news_item = NewsItem.find(params[:id]) respond_to do |format| format.html # show.rhtml format.xml { render :xml => @news_item.to_xml } end end end
  • 5. # == Schema Information # # Table name: news_items # # id :integer(4) not null, primary key # heading :string(255) # author :string(255) # body :text # created_at :datetime # updated_at :datetime # class NewsItem < ActiveRecord::Base end
  • 6. So it’s easy to provide XML via to_xml, right?
  • 7. But what if a legacy XML format is imposed?
  • 8. <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <newsletter> <summary> <title>The Trinity Tribune</title> <date>June 9th, 2009</date> </summary> <feature> <article heading=quot;Railscamp 5 a Roaring Successquot; by=quot;Lachie Coxquot;> Railscamp 5 started out so well. Saturday was awesome... </article> </feature> <article heading=quot;Bivou.ac blows Heroku away!quot; by=quot;Martin Stannardquot;> Move over Heroku, bivou.ac is here! </article> <article heading=quot;Bananas de jourquot; by=quot;Tim Lucasquot;> Bon jour, campers! Wanna share some cool code? </article> </newsletter>
  • 9. Use presenter object and Builder::XmlBuilder
  • 10. class NewsletterController < ApplicationController def show @newsletter = Newsletter.new respond_to do |format| format.xml { render :action => quot;show.xml.builderquot;, :layout => false } end end end
  • 11. remember the legacy xml format?
  • 12. <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <newsletter> <summary> <title>The Trinity Tribune</title> <date>June 9th, 2009</date> </summary> <feature> <article heading=quot;Railscamp 5 a Roaring Successquot; by=quot;Lachie Coxquot;> Railscamp 5 started out so well. Saturday was awesome... </article> </feature> <article heading=quot;Bivou.ac blows Heroku away!quot; by=quot;Martin Stannardquot;> Move over Heroku, bivou.ac is here! </article> <article heading=quot;Bananas de jourquot; by=quot;Tim Lucasquot;> Bon jour, campers! Wanna share some cool code? </article> </newsletter>
  • 13. app/views/newsletters/show.xml.builder contains Builder::XmlMarkup
  • 14. xml.instruct! xml.newsletter { xml.summary { xml.title quot;The Trinity Tribunequot; xml.date quot;#{Date.today.to_formatted_s(:rfc822)}quot; } xml.feature { @newsletter.feature_article(quot;headingquot; => feature_article.heading, quot;byquot; => feature_article.author) } @newsletter.articles.each { |article| xml.article(quot;headingquot; => article.heading, quot;byquot; => article.author) } }
  • 16. class Newsletter attr_reader :articles, :feature_article def initialize @articles = NewsItem.all_except_for_feature end def feature_article @feature_article = NewsItem.feature end # Potential for more useful methods here end
  • 17. this example is simple and contrived
  • 18. hopefully you can imagine how this technique could be useful in more complex examples
  • 19. Summary REST needs a bit of help sometimes XML Builder useful for producing XML in legacy format Presenter object can help encapsulate what is required in the XML markup

Editor's Notes