# Strict XHTML compliant ajax library

**URL:** <https://www.ruby-forum.com/t/strict-xhtml-compliant-ajax-library/161544>\
**Category:** Rails\
**Created:** [February 27, 2009, 8:20am UTC](https://www.ruby-forum.com/t/strict-xhtml-compliant-ajax-library/161544 "2009-02-27T08:20:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wanyixue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/958977/32.png) [@wanyixue](https://www.ruby-forum.com/u/wanyixue)\
**Post date:** [February 27, 2009, 8:20am UTC](https://www.ruby-forum.com/t/strict-xhtml-compliant-ajax-library/161544/1 "2009-02-27T08:20:09Z")

</div>

problem : i have to develope a app using ajax features and it has to run  
in an environment(web tv related) which is very strict about XHTML  
compliance.

and ajax codes generated by rails doesnt seem to be compliant.  
(they work on normal webpages , but not in the webtv env)

other than writing my own ajax codes and including them as helpers.

is there any other way ?

thanks

---

<div class="post-metadata">

**Author:** ![wanyixue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/958977/32.png) [@wanyixue](https://www.ruby-forum.com/u/wanyixue)\
**Post date:** [February 27, 2009, 2:19pm UTC](https://www.ruby-forum.com/t/strict-xhtml-compliant-ajax-library/161544/2 "2009-02-27T14:19:05Z")

</div>

Lin Wj wrote:

> problem : i have to develope a app using ajax features and it has to run  
> in an environment(web tv related) which is very strict about XHTML  
> compliance.
> 
> and ajax codes generated by rails doesnt seem to be compliant.  
> (they work on normal webpages , but not in the webtv env)
> 
> other than writing my own ajax codes and including them as helpers.
> 
> is there any other way ?

Install my assert\_xpath, and activate its assert\_javascript.

(This currently uses Javascript-PurePerl, and I hope to upgrade that to  
a Ruby  
solution shortly.)

Each page needs a test case like this:

def test\_foo\_is\_tidy  
get :foo  
assert\_tidy  
end

If you put “Strict XHTML” into your DOCTYPE, then tidy should enforce  
that.

Next, to test an Ajax call, you would do this:

xhr :get, :xhr\_change\_the\_frob  
assert\_js\_replace\_html :frob do  
assert\_xpath :‘form/input[@name = “baz” and @value = “42”]’  
end

assert\_js\_replace\_html lexes the returned JavaScript, finds the  
Element.update()  
command, and parses the XHTML inside it. The do-end block sees that  
XHTML, so  
you can do further queries on it.

All these tests will fail if the XHTML has a single ill-formed tag.

At my day-job, we enforce strict “Transitional XHTML”, even though we  
only  
target wildly forgiving browsers, and even though our production code  
could get  
away with sloppy HTML. We do this because enforcing XHTML makes all our  
view  
tests much easier to write.

–  
Phlip
