将 XML API 数据解析到 Rails 应用程序

发布于 2024-10-04 10:25:11 字数 1890 浏览 2 评论 0原文

我一直在尝试谷歌并找到一些关于如何执行此操作的指南或提示,但无济于事。我什至不知道标题是否正确。我不知道这个术语是否是元编程,或者只是将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文