- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有一个 XML 格式的故事集。我想解析该文件并将每个故事作为哈希或 Ruby 对象返回,以便我可以在 Ruby 脚本中进一步操作数据。
是否Nokogiri支持这个,还是有更好的工具/库可以使用?
XML 文档具有以下结构,通过 Pivotal Tracker's web API 返回:
<?xml version="1.0" encoding="UTF-8"?>
<stories type="array" count="145" total="145">
<story>
<id type="integer">16376</id>
<story_type>feature</story_type>
<url>http://www.pivotaltracker.com/story/show/16376</url>
<estimate type="integer">2</estimate>
<current_state>accepted</current_state>
<description>A description</description>
<name>Receivable index listing will allow selection viewing</name>
<requested_by>Tony Superman</requested_by>
<owned_by>Tony Superman</owned_by>
<created_at type="datetime">2009/11/04 15:49:43 WST</created_at>
<accepted_at type="datetime">2009/11/10 11:06:16 WST</accepted_at>
<labels>index ui,receivables</labels>
</story>
<story>
<id type="integer">17427</id>
<story_type>feature</story_type>
<url>http://www.pivotaltracker.com/story/show/17427</url>
<estimate type="integer">3</estimate>
<current_state>unscheduled</current_state>
<description></description>
<name>Validations in wizards based on direction</name>
<requested_by>Matthew McBoggle</requested_by>
<created_at type="datetime">2009/11/17 15:52:06 WST</created_at>
</story>
<story>
<id type="integer">17426</id>
<story_type>feature</story_type>
<url>http://www.pivotaltracker.com/story/show/17426</url>
<estimate type="integer">2</estimate>
<current_state>unscheduled</current_state>
<description>Manual payment needs a description field.</description>
<name>Add description to manual payment</name>
<requested_by>Tony Superman</requested_by>
<created_at type="datetime">2009/11/17 15:10:41 WST</created_at>
<labels>payment process</labels>
</story>
<story>
<id type="integer">17636</id>
<story_type>feature</story_type>
<url>http://www.pivotaltracker.com/story/show/17636</url>
<estimate type="integer">3</estimate>
<current_state>unscheduled</current_state>
<description>The SMS and email templates needs to be editable by merchants.</description>
<name>Notifications are editable by the merchant</name>
<requested_by>Matthew McBoggle</requested_by>
<created_at type="datetime">2009/11/19 16:44:08 WST</created_at>
</story>
</stories>
最佳答案
您可以利用 ActiveSupport 中的哈希扩展。然后你只需要在 Nokogiri 中解析你的文档,然后将节点集结果转换为哈希。此方法将保留属性类型(例如整数、日期、数组)。 (当然,如果您使用的是 Rails,则不必要求/包括主动支持或 nokogiri,如果您的环境中有的话。我假设这里是纯 Ruby 实现。)
require 'rubygems'
require 'nokogiri'
require 'activesupport'
include ActiveSupport::CoreExtensions::Hash
doc = Nokogiri::XML.parse(File.read('yourdoc.xml'))
my_hash = doc.search('//story').map{ |e| Hash.from_xml(e.to_xml)['story'] }
这将生成一个哈希数组(每个故事节点一个),并保留基于属性的类型,如下所示:
my_hash.first['name']
=> "Receivable index listing will allow selection viewing"
my_hash.first['id']
=> 16376
my_hash.first['id'].class
=> Fixnum
my_hash.first['created_at'].class
=> Time
关于xml - 将 XML 集合(Pivotal Tracker 故事)转换为 Ruby 哈希/对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1780879/
我要在这里做的是遍历Storybook故事,以便可以对它们进行视觉回归测试: const puppeteer = require('puppeteer'); const { toMatchImageS
有人可以帮我解释一下涉及老虎机的 Rasa 故事吗: ## story with email * intent_request_email - utter_request_email * in
我们能够实现与 Instagram Stories 的共享,但无法实现与 Facebook Stories 的共享,如下 these指示 。尽管已安装并更新 Facebook 应用,Android 仍
我在使用 Facebook 开放图表故事时遇到问题。我只想发布一个带有对象标题的故事。我尝试使用开放图形对象调试器,我可以清楚地看到 og:title 已定义,但我发布的提要中没有标题。 我也尝试使用
如何将数据从 .properties 文件动态加载到 jBehave 故事文件?我一直在我的故事文件中使用 $ ,例如: When the stock is traded at price : $ T
我是 jbehave 的新手 我正在尝试通过 junit 执行 jbehave。 jbehave 似乎只从类路径加载故事文件。是否可以将其配置为从用户定义的路径中获取故事文件。 public clas
我们刚刚开始考虑使用 JBehave 进行验收测试,我想知道使用它的人是如何组织故事的编写和故事文件的存储的。目前只是在开发它们,所以我们将故事文件与实现它们的 Java 代码一起存储在资源文件夹中。
我正在尝试按顺序运行 jbehave 故事。 我的集成测试包结构如下所示 src/it/some/package/name/packageA/a.story src/it/some/package/n
我有一个 jBehave 故事如下; Scenario: Setup test GivenStories: common/story_1.story, common/sto
有人可以帮我运行一个 JBehave 故事吗?我在 Eclipse 中有一个 Maven 项目。 故事是: Meta: @author Nikolay Vasilev @bdd-talk: BG JU
我们有一个 Web 开发项目团队,我们决定使用单个存储库及其优缺点。我们将待办事项分成 Jira 故事,每个故事都有几个 FE 和 BE 任务。喜欢: ABC-1 显示猫 1.1. ABC-2 [FE
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
在我们公司,我们目前正在尝试建立故事 map (Jeff Patton)的概念。 我有以下问题:- 在具有交叉问题/任务的故事 map 中会发生什么?我们有贯穿整个项目的事件。故事 map 中的这些事
我想获得与远程 GIT 和 SVN 存储库同步的本地 GIT 存储库。 我正在执行的步骤如下: > git push Everything up-to-date > git pull Already
目前我所有的 .stories 文件都保存在 stories 目录中。随着我添加更多组件,它会增长。 相反,我想根据 Storybook 站点上的文档在组件级别添加每个组件的 .stories 文件:
我在网上读到 snapchat 和 instagram 有不同的方法来捕获视频,而不是在 Android 中使用相机 API,这允许它们向捕获的内容添加过滤器/贴纸等。 任何人都可以建议解决这个问题的
在 let returnTrip = Page(story: .ReturnTrip) 中它给了我们错误。我真的不知道为什么1 enum Story { case ReturnTrip (String
我们刚刚开始将Jira(带有Jira Agile插件-Scrum模板)用于我们的问题跟踪程序和敏捷计划。 我对故事和改进之间的差异(或预期的差异)感到困惑。我们所有的“东西”都写成故事。这些故事描述了
我正在为一个网站设计一个数据库,该数据库将至少表示 4 种不同的对象类型(文章、博客文章、照片、故事),每一种都有足够不同的数据要求来保证他们自己的表。我们希望用户能够发表任何这些类型的评论。评论的数
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我是一名优秀的程序员,十分优秀!