[英]How to read xml file into vb/C#.net to show in grid using data table?
我想在 C#.NET 中讀取這個 quiz.xml 文件,以使用數據表在網格中顯示。 稍后我想將此數據插入到我實際的 sql server 數據庫中。
我不知道如何做到這一點......所以任何人都可以幫助我......提前感謝......謝謝。
quiz.xml :點擊這里下載
<?xml version="1.0" encoding="UTF-8"?>
<quiz xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="quiz.xsd">
<mchoice>
<question>What is the capital city of Australia?</question>
<answer>Sydney</answer>
<answer correct="yes">Canberra</answer>
<answer>Melbourne</answer>
<answer>Gold Coast</answer>
</mchoice>
<mchoice>
<question>Launceston is the second largest city in which Australian state?</question>
<answer>Victoria</answer>
<answer>New South Wales</answer>
<answer correct="yes">Tasmania</answer>
<answer>Western Australia</answer>
</mchoice>
<mchoice>
<question>Which state has the famous 'Twelve Apostles' ?</question>
<answer correct="yes">Victoria</answer>
<answer>South Australia</answer>
<answer>New South Wales</answer>
<answer>Western Australia</answer>
</mchoice>
<mchoice>
<question>Which is a popular ski resort in NSW?</question>
<answer correct="yes">Perisher Blue</answer>
<answer>Mt. Buller</answer>
<answer>Mt. Baw-Baw</answer>
<answer>Lake Mountain</answer>
</mchoice>
<mchoice>
<question>Which of the following is NOT Australian native animals?</question>
<answer>Kangaroo</answer>
<answer correct="yes">Penguin</answer>
<answer>Koala</answer>
<answer>Wombat</answer>
</mchoice>
<mchoice>
<question>Which city has an extensive tram network?</question>
<answer>Sydney</answer>
<answer correct="yes">Melbourne</answer>
<answer>Adelaide</answer>
<answer>Ballarat</answer>
</mchoice>
<mchoice>
<question>What is known as 'The Silver City' in Australia?</question>
<answer>Alice Springs</answer>
<answer correct="yes">Broken Hill</answer>
<answer>Ballarat</answer>
<answer>Silverton</answer>
</mchoice>
<mchoice>
<question>In which location the war movie 'Thin Red Line' was taken?</question>
<answer>Anglesea</answer>
<answer>Apollo Bay</answer>
<answer>Margaret River</answer>
<answer>Monkey Mia</answer>
<answer correct="yes">Townsville</answer>
</mchoice>
<mchoice>
<question>Which is NOT true about Uluru ?</question>
<answer>It is the world biggest monolith located in the centre of Australian continent</answer>
<answer>It was named 'Ayers Rock' by European explorer William Gosse in 1873</answer>
<answer correct="yes">Aboriginal people encourage tourists to climb Uluru</answer>
<answer>The area contains carvings and paintings by Aboriginal people</answer>
</mchoice>
<mchoice>
<question>What is so special about Longreach?</question>
<answer>The place where a blacksmith named Thomas Hiscock found the first gold that triggerred gold rush</answer>
<answer>The town has an expansive, well-preserved penal colony of Australia's early history</answer>
<answer correct="yes">The first commercial flight by Qantas took from this town in 1921</answer>
<answer>None of these answers are correct</answer>
</mchoice>
</quiz>
您應該使用"System.Data.DataTable"
類的"ReadXml"
方法並通過它傳遞xml數據(甚至文件路徑!),然后通過設置"DataSource"
屬性將網格視圖綁定到表。
希望能幫助到你。
干杯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.