D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
td-agent
/
embedded
/
lib
/
ruby
/
gems
/
2.1.0
/
doc
/
nokogiri-1.8.1
/
ri
/
Nokogiri
/
XML
/
SAX
/
Filename :
cdesc-SAX.ri
back
Copy
U:RDoc::NormalModule[iI"SAX:ETI"Nokogiri::XML::SAX;T0o:RDoc::Markup::Document:@parts[o;;[ : @fileI"+ext/nokogiri/html_sax_parser_context.c;T:0@omit_headings_from_table_of_contents_below0o;;[ ; I"ext/nokogiri/nokogiri.c;T; 0o;;[ ; I""ext/nokogiri/xml_sax_parser.c;T; 0o;;[ ; I"*ext/nokogiri/xml_sax_parser_context.c;T; 0o;;[ ; I"'ext/nokogiri/xml_sax_push_parser.c;T; 0o;;[o:RDoc::Markup::Paragraph;[I"LSAX Parsers are event driven parsers. Nokogiri provides two different ;TI"Mevent based parsers when dealing with XML. If you want to do SAX style ;TI"7parsing using HTML, check out Nokogiri::HTML::SAX.;To:RDoc::Markup::BlankLine o;;[ I"EThe basic way a SAX style parser works is by creating a parser, ;TI"Jtelling the parser about the events we're interested in, then giving ;TI"Fthe parser some XML to process. The parser will notify you when ;TI"@it encounters events you said you would like to know about.;T@!o;;[I"OTo register for events, you simply subclass Nokogiri::XML::SAX::Document, ;TI"Eand implement the methods for which you would like notification.;T@!o;;[I"MFor example, if I want to be notified when a document ends, and when an ;TI"5element starts, I would write a class like this:;T@!o:RDoc::Markup::Verbatim;[I"5class MyDocument < Nokogiri::XML::SAX::Document ;TI" def end_document ;TI"' puts "the document has ended" ;TI" end ;TI" ;TI"/ def start_element name, attributes = [] ;TI" puts "#{name} started" ;TI" end ;TI" end ;T:@format0o;;[I"LThen I would instantiate a SAX parser with this document, and feed the ;TI"parser some XML;T@!o; ;[ I"# Create a new parser ;TI"=parser = Nokogiri::XML::SAX::Parser.new(MyDocument.new) ;TI" ;TI" # Feed the parser some XML ;TI"&parser.parse(File.open(ARGV[0])) ;T;0o;;[I"LNow my document handler will be called when each node starts, and when ;TI"Jthen document ends. To see what kinds of events are available, take ;TI",a look at Nokogiri::XML::SAX::Document.;T@!o;;[ I"NTwo SAX parsers for XML are available, a parser that reads from a string ;TI"Jor IO object as it feels necessary, and a parser that lets you spoon ;TI"Kfeed it XML. If you want to let Nokogiri deal with reading your XML, ;TI"Iuse the Nokogiri::XML::SAX::Parser. If you want to have fine grain ;TI"Hcontrol over the XML input, use the Nokogiri::XML::SAX::PushParser.;T; I"%lib/nokogiri/xml/sax/document.rb;T; 0o;;[ ; I"#lib/nokogiri/xml/sax/parser.rb;T; 0o;;[ ; I"+lib/nokogiri/xml/sax/parser_context.rb;T; 0o;;[ ; I"(lib/nokogiri/xml/sax/push_parser.rb;T; 0; 0; 0[ [ [ [[I" class;T[[:public[ [:protected[ [:private[ [I" instance;T[[;[ [;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ; 0; 0[ I"!ext/nokogiri/html_document.c;T@R@U@X@[I"Nokogiri::XML;TcRDoc::NormalModule