require 'libxml' # Validates using LibXML via the libxml-ruby[http://libxml.rubyforge.org/] gem. module AssertValidContent::LibXML Installed = true # Validates HTML and XHTML class HTMLValidator < 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 @errors.empty? end protected def parser( content ) #:nodoc: ::LibXML::XML::HTMLParser.string content end end module Assertions def assert_valid_html( *srcs, &blk ) assert_valid_content ::AssertValidContent::LibXML::HTMLValidator, *srcs, &blk end end # Validates XML class XMLValidator < HTMLValidator protected def parser( content ) #:nodoc: ::LibXML::XML::Parser.string content end end module Assertions def assert_valid_xml( *srcs, &blk ) assert_valid_content ::AssertValidContent::LibXML::XMLValidator, *srcs, &blk end end end