require 'assert_valid_content/validator' # Validates using LibXML via the libxml-ruby[http://libxml.rubyforge.org/] gem. module AssertValidContent::LibXML # +true+ if required dependencies are installed Installed = begin gem( 'libxml-ruby', '~> 1.1' ) require 'libxml' true rescue Gem::LoadError false end # Validates HTML and XHTML class AssertValidContent::LibXML::HTML < AssertValidContent::Validator def validate( content ) #:nodoc: ::LibXML::XML::Error.set_handler { |err| @errors << err } begin doc = self.parser( content ).parse rescue ::LibXML::XML::Error ; end end protected def parser( content ) #:nodoc: ::LibXML::XML::HTMLParser.string content end end # Validates XML class AssertValidContent::LibXML::XML < HTML protected def parser( content ) #:nodoc: ::LibXML::XML::Parser.string content end end end