XML/Input: Difference between revisions

376 bytes added ,  15 years ago
add Ruby
(→‎{{header|Python}}: Task changed requiring update)
(add Ruby)
Line 250:
for i in doc.getElementsByTagName("Student"):
print i.getAttribute("Name")</lang>
 
=={{header|Ruby}}==
{{libheader|REXML}}
<lang ruby>require 'rexml/document'
include REXML
 
doc = Document.new(File.new("sample.xml"))
# or
# doc = Document.new(xml_string)
 
# without using xpath
doc.each_recursive do |node|
puts node.attributes["Name"] if node.name == "Student"
end
 
# using xpath
doc.each_element("*/Student") {|node| puts node.attributes["Name"]}</lang>
 
=={{header|Tcl}}==
Anonymous user