【发布时间】:2010-11-29 00:20:04
【问题描述】:
我一直在尝试在 Google 上找到一些有关如何执行此操作的指南或提示,但无济于事。我什至不知道标题是否正确。我不知道它是元编程,还是只是将 XML 数据解析到 Rails。
假设我有一个同意提供 XML API 来向我的网站提供数据的第三方。我想接收数据并将其存储在我的模型中。我通过 SO 进行了检查,发现这个链接部分回答了我的问题:Parse then Store XML Data from API in Ruby on Rails,但我想知道应用于我的第三方方法的确切方法。
样本属性信息请求
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 解析信息并将其存储到我的模型?
其实,有什么链接可以让我了解所有这些吗?
非常感谢!
【问题讨论】:
-
这不是元编程;) 解析是您所需要的。查看 Nokogiri 库 - 它非常适合 XML 解析。
标签: ruby-on-rails xml xml-parsing