将 XML API 数据解析到 Rails 应用程序
我一直在尝试谷歌并找到一些关于如何执行此操作的指南或提示,但无济于事。我什至不知道标题是否正确。我不知道这个术语是否是元编程,或者只是将 XML 数据解析到 Rails。
假设我有一个第三方同意提供 XML API 来向我的网站提供数据。我想接收数据并将其存储在我的模型中。我检查了一下,发现这个链接部分回答了我的问题: 在 Ruby on Rails 中解析并存储来自 API 的 XML 数据,但我想知道应用到我的第三方方法的确切方法。
示例属性信息请求
http://third-party.com/xmlapi/PropertyInformation.php?PropertyNumber=113
示例属性信息请求结果
<?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>
我的模型列中有 PropertyNumber
。如何使用结构化 URL 编写解析信息并将其存储到我的模型中?
其实有什么链接可以让我了解所有这些吗?
非常感谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于如此短的 xml,这可能对您有帮助/最简单:
http:// /ryandaigle.com/articles/2006/06/27/whats-new-in-edge-rails-create-a-hash-from-xml
对于 xml 解析:
http://developer.yahoo.com/ruby/ruby-xml.html
使用Nokogiri:
http://nokogiri.org/tutorials/searching_a_xml_html_document.html
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