【问题标题】:What is the best way to read/parse the XML files [closed]读取/解析 XML 文件的最佳方法是什么[关闭]
【发布时间】:2012-05-20 05:30:23
【问题描述】:

我有一堆这些 XML 文件,我想读取它们并将数据存储在 SQL 表中。读取/解析 XML 文件的最佳方法是什么?我正在使用 ASP.NET 4.0 和 SQL Server 2008。我非常擅长 C#/VB 和 asp.net,但对 XML 没有太多经验。基本上这些是多项选择题,并且有答案。任何帮助将不胜感激。谢谢。

<assessmentItem xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p0 imsqti_v2p0.xsd" identifier="choice" adaptive="false" timeDependent="false" title="001157" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier">
        <correctResponse>
            <value>A</value>
        </correctResponse>
    </responseDeclaration>
    <outcomeDeclaration identifier="SCORE" cardinality="single" baseType="integer">
        <defaultValue>
            <value>0</value>
        </defaultValue>
    </outcomeDeclaration>
    <stylesheet href="stylesheet/scip.css" type="text/css" />
    <itemBody>
        <span class="class1">
            <b>Nick had eight marbles. He found four more.<br />
                <br />
            </b>
        </span>
        <div class="class2">
            <span class="class1">
                <b>
                    <img src="images/41047.jpg" alt="" />
                </b>
            </span>
        </div>
        <span class="class1">
            <b>How many marbles does Nick have now?</b>
        </span>
        <choiceInteraction responseIdentifier="RESPONSE" shuffle="false" maxChoices="1">
            <simpleChoice identifier="A">
                <span class="class1">12</span>
                <rubricBlock>
                    <span class="class1" >
                        <b>Correct</b>
                    </span>
                </rubricBlock>
            </simpleChoice>
            <simpleChoice identifier="B">
                <span class="class1">8</span>
                <rubricBlock>
                    <span class="class1" >Chose a number from the stem</span>
                </rubricBlock>
            </simpleChoice>
            <simpleChoice identifier="C">
                <span class="class1">4</span>
                <rubricBlock>
                    <span class="class1" >Subtracted</span>
                </rubricBlock>
            </simpleChoice>
        </choiceInteraction>
    </itemBody>
    <responseProcessing template="http://www.imsglobal.org/question/qti_v2p0/rptemplates/match_correct" />
</assessmentItem>

【问题讨论】:

  • 你说这是“多项选择”,实际上已经注定了自己的命运。由于这不是论坛,因此预计问题会有明确的答案。如果您能够证明您自己尝试过一些您似乎没有做过的事情,这也很有帮助。

标签: asp.net .net sql xml


【解决方案1】:

您的标题具有误导性。你问的是What is the best way to read/parse the XML files?,和Storing XML in a database没什么关系。

我建议不要偷懒,阅读文档如何做到这一点。无论您使用什么语言,解析 XML 都是非常常见的任务。您会在网上找到大量示例。

【讨论】:

  • +1 看看他/她关于书籍的其他问题(5 分钟前),我告诉用户也去谷歌
【解决方案2】:

基本上这些是多项选择题及其答案。读取/解析 XML 文件的最佳方式是什么?

我们现在就让你解决问题。看这里,你需要阅读一些文章,鉴于你擅长 C# 和 VB.Net,这应该不是问题:

Google - Linq To XML examples

使用此技术的一种方法是使用 XDoc 加载 XML,然后将 XML 解析为类对象模型,使用带有匿名类型的 LinqToXML 创建类的选择和答案列表。

Official Microsoft examples

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-14
    • 2010-09-30
    • 2015-08-21
    • 1970-01-01
    • 2020-03-14
    • 2013-12-20
    相关资源
    最近更新 更多