Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/XML-XPath/Ruby/xml-xpath.rb
Normal file
16
Task/XML-XPath/Ruby/xml-xpath.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#Example taken from the REXML tutorial (http://www.germane-software.com/software/rexml/docs/tutorial.html)
|
||||
require "rexml/document"
|
||||
include REXML
|
||||
#create the REXML Document from the string (%q is Ruby's multiline string, everything between the two @-characters is the string)
|
||||
doc = Document.new(
|
||||
%q@<inventory title="OmniCorp Store #45x10^3">
|
||||
...
|
||||
</inventory>
|
||||
@
|
||||
)
|
||||
# The invisibility cream is the first <item>
|
||||
invisibility = XPath.first( doc, "//item" )
|
||||
# Prints out all of the prices
|
||||
XPath.each( doc, "//price") { |element| puts element.text }
|
||||
# Gets an array of all of the "name" elements in the document.
|
||||
names = XPath.match( doc, "//name" )
|
||||
Loading…
Add table
Add a link
Reference in a new issue