The ancient Western Xia kingdom (1038–1227 AD) encompassed a vast expanse of land, overlapping regions of what is now Ningxia, Gansu and Shaanxi provinces. Established by the nomadic Dangxiang clan of Qiang ancestry, the kingdom had twelve kings and developed its own written language, which combines influences from Mongolian, Tibetan and Chinese. The Western Xia territory survived prior to independence by playing off the Song or Liao dynasties against each other. In 1038, Li Yuanhao, leader of Western Xia, was militarily powerful enough to oppose Song jurisdiction and thus this third kingdom was created. A prosperous period ensued as the kingdom benefited from controlling the trade routes into central Asia. The new era saw a time of great cultural development, a state academy was erected, and future officials took Confucian examinations. Less emphasis, however, was placed on military matters, and in 1227 the Western Xia were obliterated by the Mongol empire of Genghis Khan.