<P> In the northwest, the Song were in conflict with the Western Xia, since they occupied what the Song considered as Chinese land lost during the Tang dynasty . The Song utilized the walls built during the reign of Qin's King Zhaoxiang of the Warring States period, making it the Song--Western Xia border, but the topography of the area was not as sharp and distinct as the Song--Liao defences to the east . The border general Cao Wei (曹 瑋; 973--1030) deemed the Old Wall itself insufficient to slow a Tangut cavalry attack, and had a deep trench dug alongside . This trench, between 15 and 20 metres (49 and 66 feet) in width and depth, proved an effective defence, but in 1002 the Tanguts caught the Song patrollers off guard and filled the trench to cross the Old Wall . Later, in 1042, the Tanguts turned the trench against the Song by removing the bridges over it, thereby trapping the retreating army of Ge Huaimin (葛懷敏) before annihilating it at the Battle of Dingchuan Fortress (定 川 寨). </P> <P> Despite the war with the Western Xia, the Song also settled land disputes with them by referring to prior agreements, as with the Liao . However, soon after the Jin dynasty overthrew the Liao dynasty, the Jurchens sacked the Song capital in 1127 during the Jin--Song wars, causing the Song court to flee south of the Yangtze River . For the next two and a half centuries, the Great Wall played no role in Han Chinese geopolitics . </P> <P> In the 13th century, the Mongol leader Genghis Khan, once a vassal of the Jurchens, rose up against the Jin dynasty . In the ensuing Mongol conquest of the Jin dynasty, the nomadic invaders avoided direct attacks on the Jin fortifications . Instead, when they could, the Mongols simply rode around the walls; an effective example of this tactic is in 1211, when they circumvented the substantial fortress in Zhangjiakou and inflicted a terrible defeat upon the Jin armies at the Battle of Yehuling . The Mongols also took advantage of lingering Liao resentment against the Jin; the Khitan defenders of the garrisons along the Jin walls, such as those in Gubeikou, often preferred to surrender to the Mongols rather than fight them . The only major engagement of note along the main Great Wall line was at the heavily defended Juyong Pass: instead of laying siege, the Mongol general Jebe lured the defenders out into an ambush and charged in through the opened gates . In 1215, Genghis Khan besieged, captured, and sacked the Jin capital of Yanjing (modern - day Beijing). The Jin dynasty eventually collapsed following the siege of Caizhou in 1234 . Western Xia had already fallen in 1227, and the Southern Song resisted the Mongols until 1279 . </P> <P> With that, the Yuan dynasty, established by Genghis Khan's grandson Khublai Khan, became the first foreign dynasty to rule all of China . Despite being the head of the Mongol Empire, Khublai Khan's rule over China was not free from the threat of the steppe nomads . The Yuan dynasty faced challenges from rival claimants to the title of Great Khan and from rebellious Mongols in the north . Khublai Khan dealt with such threats by using both military blockades and economic sanctions . Although he established garrisons along the steppe frontier from the Juyan Lake Basin in the far west to Yingchang in the east, Khublai Khan and the Yuan emperors after him did not add to the Great Wall (except for the ornate Cloud Platform at Juyong Pass). When the Venetian traveller Marco Polo wrote of his experiences in China during the reign of Khublai Khan, he did not mention a Great Wall . </P>

When did the great wall of china build