The simplest way to achieve this end is typing this:
$ xwd -out /tmp/shot.xwd
And then select the window you want to "photograph" with your mouse pointer.
Once you obtain the dump, convert will help you convert to the format of choice.
$ convert /tmp/shot.xwd ~/shots/xterm.png
or
$ convert /tmp/shot.xwd ~/shots/xterm.jpg