oga/lib/oga/oga.rb

58 lines
1.2 KiB
Ruby
Raw Normal View History

module Oga
##
# Parses the given XML document.
#
# @example
# document = Oga.parse_xml('<root>Hello</root>')
#
# @see [Oga::XML::Lexer#initialize]
#
# @return [Oga::XML::Document]
#
def self.parse_xml(xml, options = {})
2015-06-15 22:51:51 +00:00
XML::Parser.new(xml, options).parse
end
##
# Parses the given HTML document.
#
# @example
# document = Oga.parse_html('<html>...</html>')
#
# @see [Oga::XML::Lexer#initialize]
#
# @return [Oga::XML::Document]
#
def self.parse_html(html, options = {})
2015-06-15 22:51:51 +00:00
HTML::Parser.new(html, options).parse
end
##
# Parses the given XML document using the SAX parser.
#
# @example
# handler = SomeSaxHandler.new
#
# Oga.sax_parse_html(handler, '<root>Hello</root>')
#
# @see [Oga::XML::SaxParser#initialize]
#
def self.sax_parse_xml(handler, xml, options = {})
XML::SaxParser.new(handler, xml, options).parse
end
##
# Parses the given HTML document using the SAX parser.
#
# @example
# handler = SomeSaxHandler.new
#
# Oga.sax_parse_html(handler, '<script>foo()</script>')
#
# @see [Oga::XML::SaxParser#initialize]
#
def self.sax_parse_html(handler, html, options = {})
HTML::SaxParser.new(handler, html, options).parse
end
end # Oga