Created
November 9, 2010 12:30
-
-
Save janv/669029 to your computer and use it in GitHub Desktop.
Example for using the nokogiri reader
This file contains 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
require 'rubygems' | |
require 'nokogiri' | |
doc = Nokogiri::XML.fragment(<<-eoxml) | |
<bla> | |
<bing/> | |
<bong/> | |
</bla> | |
<blubb>asdasd</blubb> | |
eoxml | |
# puts doc | |
reader = Nokogiri::XML::Reader(<<-eoxml, nil, nil, Nokogiri::XML::ParseOptions::DEFAULT_XML ^ Nokogiri::XML::ParseOptions::NOBLANKS) | |
<doc> | |
<bla> | |
<bing a="1" b="2"/> | |
<bong/> | |
</bla> | |
<blubb>111111</blubb> | |
<blubb>222222</blubb> | |
<blubb>333333</blubb> | |
<blubb>444444</blubb> | |
</doc> | |
eoxml | |
reader.each do |node| | |
puts "#{' '*node.depth}Name: #{node.name} Type: #{node.node_type}" | |
puts node.outer_xml | |
puts '--------------------------------' | |
end | |
# node type 15 = end node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment