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