I forgot:
I commented the tidy import because I do not have the tidy lib in my system, so I also nodified for example:

document = tidy.parseString(o)

to

document = o

This should be reverted in the code

Read More...