Skip to content

Instantly share code, notes, and snippets.

@MFQ
Created November 28, 2017 11:02
Show Gist options
  • Save MFQ/a92816a81738a2af1963b0749b9739ee to your computer and use it in GitHub Desktop.
Save MFQ/a92816a81738a2af1963b0749b9739ee to your computer and use it in GitHub Desktop.
require 'nokogiri'
xml_source = '<item id="0001" type="donut">
<batters>
<batter>Regular</batter>
<batter data-target="neat">Regular</batter>
<batter>Regular</batter>
</batters>
</item>'
doc = Nokogiri::XML(xml_source)
doc.xpath('//batter[@data-target="neat"]').first.text
## Will return inner text
doc.xpath('//batter[@data-target="neat"]').first.values
## Will return date-target value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment