I would not get the D40 if it were me. The D40 has limited lenses that you can get for it. With the D40 you have to have an autofocus in the lens, where on something like the D80 all Nikon fitted lenses will work, as there is an autofocus in the camera its self.
The Canon XTi and the D40 are not comparable. But the D80 and the XTi are. If you are looking just at the D40 and XTi, go for the XTi. I personally have a D50 and love it! Also I would recommend a Sigma 70mm-300mm lens to go along with that!
JMHO
Matt