代码之家  ›  专栏  ›  技术社区  ›  Victor

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

  •  1
  • Victor  · 技术社区  · 15 年前

    我一直试图在谷歌上找到一些如何做到这一点的指南或头条,但没有效果。我甚至不知道这个头衔是否正确。我不知道这个术语是元编程,还是仅仅将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来解析和存储模型中的信息?

    事实上,我能学到这些的链接吗?

    非常感谢!

    1 回复  |  直到 9 年前