<P> The city's first commercial railway, Tianjin - Lugouqiao Railway, was built from 1895 to 1897 with British financing . It ran from the Marco Polo Bridge to Tianjin . The rail terminus was extended closer to the city to Fengtai and then to Majiapu, just outside Yongdingmen, a gate of the Outer City wall . The Qing court resisted the extension of railways inside city walls . Foreign powers who seized the city during the Boxer Rebellion extended the railway inside the outer city wall to Yongdingmen in 1900 and then further north to Zhengyangmen (Qianmen) just outside the Inner City wall in 1903 . They built an eastern spur to Tongzhou to carry grain shipped from the south on the Grand Canal . This extension breached the city wall at Dongbianmen . The Lugouqiao - Hankou Railway, financed by French - Belgian capital and built from 1896 to 1905, was renamed Beijing - Hankou Railway after it was routed to Qianmen from the west . This required the partial demotion of the Xuanwumen barbican . The completion of the Beijing--Fengtian Railway in 1907 required a similar break in Chongwenmen's fortification . Thus, began the tearing down of city gates and walls to make way for rail transportation . The first railway in China built without foreign assistance was the Imperial Beijing - Zhangjiakou Railway . Built from 1905 to 1909, it was designed by Zhan Tianyou and terminated just outside Xizhimen . By the late Qing dynasty, Beijing had rail connections to Hankou (Wuhan), Pukou (Nanjing), Fengtian (Shenyang) and Datong, and was a major railway hub in North China . </P> <P> The Qing dynasty was overthrown in the Xinhai Revolution of 1911 but the capital of the newly founded Republic of China remained in Beijing as former Qing general Yuan Shikai took control of the new government from revolutionaries in the south . Yuan and successors from his Beiyang Army ruled the Republic from Beijing until 1928 when Chinese Nationalists reunified the country through the Northern Expedition and moved the capital to Nanjing . Beijing was renamed Beiping . In 1937, a clash between Chinese and Japanese troops at the Marco Polo Bridge outside Beiping triggered the outbreak of the Second Sino - Japanese War . Japanese occupiers created a collaborationist government in northern China and reverted the city's name to Beijing to serve as capital for the puppet regime . After Japan's surrender in 1945, the city returned to Chinese rule and was again renamed Beiping . During the subsequent civil war between the Chinese Nationalists and Communists, the city was peacefully transferred to Communist control in 1949 and renamed Beijing to become the capital of the People's Republic of China . </P> <P> When the Wuchang Uprising erupted in October 1911, the Qing court summoned Yuan Shikai and his powerful Beiyang Army to suppress the insurrection . As he fought revolutionaries in the south, Yuan also negotiated with them . On January 1, 1912, Dr. Sun Yat - sen, who returned from exile, founded the Republic of China in Nanjing and was elected provisional president . The new government was not recognized by any foreign powers, and Sun agreed to cede leadership to Yuan Shikai in exchange for the latter's assistance in ending the Qing dynasty . On February 12, Yuan compelled the Qing court, under the regency of Prince Chun, to abdicate . Empress Dowager Longyu signed the abdication agreement on behalf of the five - year - old Last Emperor, Puyi . The following day Sun resigned from the provisional presidency and recommended Yuan for the position . Under the terms of the imperial abdication, the Puyi would retain his dignitary title and staff and receive an annual stipend of 4 million Mexican silver dollars from the Republic . He was permitted to continue to reside in the Forbidden City for a time but was required to eventually move to the Summer Palace . His tomb and rituals were to be maintained at the expense of the Republic . The abdication ended the Qing dynasty and averted further bloodshed in the revolution . </P> <P> As a condition for ceding leadership to Yuan, Sun insisted that the provisional government remain in Nanjing . On February 14, the Provisional Senate initially voted 20--5 in favor of making Beijing the capital over Nanjing, with two votes going for Wuhan and one for Tianjin . The Senate majority wanted to secure the peace agreement by taking power in Beijing . Zhang Jian and others reasoned that having the capital in Beijing would check against Manchu restoration and Mongol secession . But Sun and Huang Xing argued in favor of Nanjing to balance against Yuan's power base in the north . Li Yuanhong presented Wuhan as a compromise . The next day, the Provisional Senate voted again, this time, 19--6 in favor of Nanjing with two votes for Wuhan . Sun sent a delegation led by Cai Yuanpei and Wang Jingwei to persuade Yuan to move to Nanjing . Yuan welcomed the delegation and agreed to accompany the delegates back to the south . Then on the evening of February 29, riots and fires broke out in all over the city . They were allegedly started by disobedient troops of Cao Kun, a loyal officer of Yuan . Disorder among military ranks spread to Tongzhou, Tianjin and Baoding . These events gave Yuan the pretext to stay in the north to guard against unrest . On March 10, Yuan was inaugurated in Beijing as the provisional president of the Republic of China . Yuan based the executive office and residence in Zhongnanhai, next to the Forbidden City . On April 5, the Provisional Senate in Nanjing voted to make Beijing the capital of the Republic and convened in Beijing at the end of the month . </P>

Who turned beijing into a walled city and extended the grand canal