The 47-year-old, who had been jobless for nine years, told the court his motive was to vent his rage against society.
He appealed against a death penalty, saying the punishment was too harsh because he had not killed anyone.
String of attacks
A string of recent attacks at Chinese schools has caused outrage and fear in China.
Seventeen people have been killed in five attacks on schools in less than two months and more than 80 injured.
The violence has prompted calls for better protection of students and raised questions about China's treatment of people with mental health problems.
Four of Xu's young victims were gravely hurt, according to official media.
Xinhua said the court decided that even though Xu did not succeed in killing his victims, "his criminal motivation was extremely despicable, his means extremely cruel, his plot especially evil".
Wen Jiabao, the Chinese premier, has said long-standing social concerns were partially to blame for the string of attacks on schoolchildren.
"We need to resolve the deep-seated causes that have resulted in these problems," Wen said in an interview with with Hong Kong-based Phoenix Television on Thursday .
"This includes handling social contradictions, resolving disputes and strengthening mediation at the grassroots level."