0

I have a XML like:

<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>

I want to deserialize the XML and I need the content not to be deserialized and want it as XML string in a property inside the main class.

Please help.

Ryan Gates
  • 4,501
  • 6
  • 50
  • 90
Logu
  • 51
  • 5
  • 1
    where does the XML come from? is it a file? – Sam I am says Reinstate Monica Dec 11 '13 at 20:14
  • `I want to deserialize the XML and I need the content not to be deserialized and want it as XML string` what does this mean? – L.B Dec 11 '13 at 20:14
  • Why would you only want to deserialize part of the xml? Also please take the time to format your code to make it clear and readable. – Ryan Gates Dec 11 '13 at 20:14
  • see http://stackoverflow.com/questions/20527872/how-can-i-turn-an-xml-document-into-an-easy-to-use-c-sharp-object/20528444#20528444, maybe it will help – PhillyNJ Dec 11 '13 at 20:17
  • Do you want to load the entire XML document as a string, or do you want to instantiate an object from the top-level element, and set the `questionBody` property to that element's inner XML tree? – Mike Strobel Dec 11 '13 at 20:38
  • Hi All, Thanks for formatting and taking time to reply. Sorry for not making everything clear in my question. I need to deserialize this XML (I knew how to deserialize XML and I knew the XMLTextAttribute option too). I want the m:math part and its children in this XML inside a property in my deserialized object as XML string. i.e., I want the m:math tag alone as it is (without deserializing). – Logu Dec 12 '13 at 05:00
  • I am clear on what am asking.. I wanted a part of the XML not to be deserialized and wanted it as is, while the other part of the file is deserialized. Please remove the hold on this question. – Logu Dec 12 '13 at 19:44
  • I got answer and thanks for trying to help me out. – Logu Dec 13 '13 at 13:43
  • @Logu Any change you can post your solution? I have a similar problem. – Darrel Miller Jun 30 '16 at 21:52

1 Answers1

1

If you have an XML file, and you want to load it as a string instead of as an XML document, than you can just read it as you would any other plain text file.

string xDocString = File.ReadAllText("XMLFile1.xml");
  • Thanks for the answer. Sorry for not making it clear in my first post. I need to deserialize this XML (I knew how to deserialize XML and I knew the XMLTextAttribute option too). I want the m:math part and its children in this XML inside a property in my deserialized object as string. i.e., I want the m:math tag alone as it is(without deserializing) . – Logu Dec 12 '13 at 05:01