1

I've been trying to Google and find some guides or heads-up on how to do this, but to no avail. I don't quite know if the title is right even. I don't know the term whether it's meta programming, or just parsing XML data to Rails.

Let's say I have this third-party who has agreed to provide XML API to feed data to my website. I would like to receive the data and store it in my model. I checked through SO and found this link which partly answers my question: Parse then Store XML Data from API in Ruby on Rails, but I would like to know the exact way to apply on my third-party's method.

Sample Property Information Request

http://third-party.com/xmlapi/PropertyInformation.php?PropertyNumber=113

Sample Property Information Request Results

<?xml version="1.0" ?>
<PropertyInformation size="1">
<Property size="12">
<propertyNumber>113</propertyNumber>
<propertyName>Kinlay House Christchurch</propertyName>
<address1>2-12 Lord Edward Street</address1>
<address2>Dublin 2</address2>
<city>Dublin</city>
<country>Ireland</country>
<description>Situated in the Temple Bar district in the heart of Dublin, Kinlay House offers a wide selection of clean and comfortable rooms that won't break the bank. Temple Bar offers visitors an unrivalled selection of bars, cafes and restaurants, all infused with a lively Irish flavour. Within easy walking distance of Grafton Street - Dublin's main shopping Street - and the vast selection of museums, galleries and tourist attractions that the city has to offer. Come and enjoy the great atmosphere and vibrant spirit! <i>YOU CAN ALSO BOOK KINLAY HOUSE CORK AND KINLAY HOUSE GALWAY ONLINE</i> Self-catering kitchen 24 hour staffing, no curfew Security lockers/luggage storage Tourist Information & booking service International pay phones Family friendly</description>
</Property>
</PropertyInformation>

I have the PropertyNumber in my model column. How do I write to parse and store the information to my model with the structured URL?

In fact, any links that I can learn all these?

Many thanks!

1
  • It's not metaprogramming ;) Parsing is what you need. Check out the Nokogiri library - it's pretty good for XML parsing. Commented Nov 28, 2010 at 15:51

1 Answer 1

4

For such short xml, this might be helpful/easiest to you:
http://ryandaigle.com/articles/2006/06/27/whats-new-in-edge-rails-create-a-hash-from-xml

For xml parsing:
http://developer.yahoo.com/ruby/ruby-xml.html

Using Nokogiri:
http://nokogiri.org/tutorials/searching_a_xml_html_document.html

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.