views:

461

answers:

5

I'd like to run validations on the static web content I'm creating. Are there any good validators for XHTML, ATOM, and CSS? (The first two would be covered by any general-purpose XML-DTD validator.)

Later

I failed to specify that I wanted local validation, not something that uses the W3C service.

+1  A: 

Markup Validation Service, by w3c, can validate XHTML.

There are also a CSS Validation Service and a Feed Validation Service.

Is that what you were looking for?

If you want to validate from inside a ruby program, here is an article explaining how to do that using this services. I didn't try it, sorry.

eKek0
Going from the question title I'd say (s)he's looking for a Ruby script that can perform the validation locally.
John Topley
+1  A: 

Check W3C Validators Ruby Gem.

W3C Validators is a Ruby wrapper for the World Wide Web Consortium's online validation services.

It supports the markup validator, the feed validator and the CSS validator.

Otherwise, W3C's Validator has a SOAP API which you can use even from Ruby, or there is an article demonstrates how to validate HTML in Ruby with libxml.

Török Gábor
+4  A: 

Nokogiri ( http://github.com/tenderlove/nokogiri/tree/master ) is great tool for parsing XML/XHTML/HTML/etc and it looks like it can validate as well:

Nokogiri::XML.parse(string_or_io, nil, nil, Nokogiri::XML::PARSE_DTDVALID)

At the moment, I don't believe that you'll find a pure ruby project that will validate your CSS directives, but there are many that will let you use ruby code to generate valid CSS.

JD Huntington
+1  A: 

Just as an info: Nokogiri 1.3.0 was released today and now has validation classes for XML inside the official release. No need to get the trunk version.

http://nokogiri.rubyforge.org/nokogiri/

Skade
+1  A: 

I use the following to validate the markup on all of our pages through our test suite: assert_valid_markup

It provides nice markup testing like:

class FooControllerTest < Test::Unit::TestCase
  def test_bar_markup
    get :bar
    assert_valid_markup
  end
end

or

class FooControllerTest < Test::Unit::TestCase
  def test_bar_markup
    assert_valid_markup "<div>Hello, world.</div>"
  end
end

# For the ultimate in convenience, use the class-level method to validate a slew of
# actions in one line. Par exemple:

class FooControllerTest < Test::Unit::TestCase
  assert_valid_markup :bar, :baz, :qux
end
mwilliams
did you delete that repository? GitHub says it doesn't exist
James A. Rosen
Hm, maybe it's a GitHub problem. The link doesn't work, but the URL does.
James A. Rosen