Last active
December 25, 2015 17:59
-
-
Save znz/7017677 to your computer and use it in GitHub Desktop.
Nokogiri::XML::Reader and attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ruby tameshi-giri.rb | |
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin11.4.2] | |
Nokogiri::VERSION = 1.6.0 | |
Nokogiri::LIBXML_VERSION = 2.8.0 | |
"value" | |
"http://example.com/" | |
% ruby tameshi-giri.rb | |
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux] | |
Nokogiri::VERSION = 1.6.0 | |
Nokogiri::LIBXML_VERSION = 2.8.0 | |
"value" | |
"http://example.com/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'nokogiri' | |
puts RUBY_DESCRIPTION | |
puts "Nokogiri::VERSION = #{Nokogiri::VERSION}" | |
puts "Nokogiri::LIBXML_VERSION = #{Nokogiri::LIBXML_VERSION}" | |
xml = <<-XML | |
<?xml version="1.0" encoding="UTF-8"?> | |
<root xmlns="http://example.com/"> | |
<foo name="value"/> | |
<bar/> | |
</root> | |
XML | |
reader = Nokogiri::XML::Reader(xml) do |config| | |
config.strict.nonet | |
end | |
reader.each do |node| | |
next unless /foo|bar/ =~ node.name | |
p node.attribute("name") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment