简体   繁体   English

如何将 xml 文件读入 vb/C#.net 以使用数据表在网格中显示?

[英]How to read xml file into vb/C#.net to show in grid using data table?

i want to read this quiz.xml file in C#.NET to show in grid using data table.我想在 C#.NET 中读取这个 quiz.xml 文件,以使用数据表在网格中显示。 n later on i want to insert this data into my actual sql server database.稍后我想将此数据插入到我实际的 sql server 数据库中。

m not getting how to do this...so can anyone please help me....thanks in advance... thanx in adv.我不知道如何做到这一点......所以任何人都可以帮助我......提前感谢......谢谢。

quiz.xml : click here to download 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>

You should use the "ReadXml" method of the "System.Data.DataTable" class and pass the xml data (or even the file path!) through it, then bind the grid view to the table by setting the "DataSource" property.您应该使用"System.Data.DataTable"类的"ReadXml"方法并通过它传递xml数据(甚至文件路径!),然后通过设置"DataSource"属性将网格视图绑定到表。

Hope it helps.希望能帮助到你。

Cheers干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM