C#XML反序列化部分XML要按原样呈现

时间:2013-12-11 20:11:29

标签: c# .net xml deserialization

我有一个XML:

<choiceQuestion>
    <questionBody>
        <p>
    Using a right Riemann sum over the given intervals, estimate
            <m:math xmlns:m="http://www.w3.org/1998/Math/MathML">
                <m:mstyle displaystyle="true">
                    <m:munderover>
                        <m:mrow>
                            <m:mo>∫</m:mo>
                        </m:mrow>
                        <m:mrow>
                            <m:mn>5</m:mn>
                        </m:mrow>
                        <m:mrow>
                            <m:mn>35</m:mn>
                        </m:mrow>
                    </m:munderover>
                    <m:mi>f</m:mi>
                    <m:mfenced>
                        <m:mrow>
                            <m:mi>t</m:mi>
                        </m:mrow>
                    </m:mfenced>
                    <m:mi>dt</m:mi>
                </m:mstyle>
            </m:math>
    .
        </p>
        <p>
            <img data-uuid="ae9daa28-5259-4006-8c46-4d6098cc902f"/>
        </p>
    </questionBody>
    <choiceInteraction interactionId="301045" singleSelect="true">
        <simpleChoice choiceId="choicea" correct="false">730</simpleChoice>
        <simpleChoice choiceId="choiceb" correct="false">661</simpleChoice>
        <simpleChoice choiceId="choicec" correct="false">564</simpleChoice>
        <simpleChoice choiceId="choiced" correct="true">474</simpleChoice>
        <simpleChoice choiceId="choicee" correct="false">325</simpleChoice>
    </choiceInteraction>
</choiceQuestion>

我想反序列化XML,我需要不反序列化的内容,并希望它在主类中的属性中作为XML字符串。

请帮忙。

1 个答案:

答案 0 :(得分:1)

如果您有一个XML文件,并且想要将其作为字符串而不是XML文档加载,那么您可以像读取任何其他纯文本文件一样将其加载。

string xDocString = File.ReadAllText("XMLFile1.xml");