BEIJING (Reuters) - A knife-wielding man on Friday wounded seven children and two bystanders outside a primary school in northwestern China, state media said, in the latest mass knifing attack.

Violent crime is rare in China compared with many other countries, but there has been a series of knife and ax attacks in recent years, many targeting children.

The suspect in Friday's incident, Lei Mingyue, 58, attacked the students in the city of Hanzhong in Shaanxi province, and injured two passersby while trying to escape, China Central Television (CCTV) said on its official microblog.

Lei, who was taken into custody and previously had been punished for theft crimes, was seeking "revenge on society", CCTV said, citing police. It was unclear about his motives.

Photographs posted by CCTV showed children being carried and rolled on a gurney to an ambulance. It said all the victims had been taken to a hospital for treatment and the incident was being investigated.

(Reporting by Michael Martina; Editing by Clarence Fernandez)