0

I am working on a calculator that lets you save your session as an XML file. This is what my example session looks like:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<BreezyCalc Version="3.0">
    <Session>
        <Constants>
            <Constant Name="myconst1" Value="12.443" />
            <Constant Name="someconst" Value="0.12e+2" />
        </Constants>
        <Variables>
            <Variable Name="myvar" Value="40.32" />
            <Variable Name="myothervar" Value="2.5" />
        </Variables>
        <Functions>
            <Function Linear="true" Name="myfunc1" M="2.8" B="-7" />
            <Function Linear="true" Name="otherfunc" M="-1" B="14.32" />
        </Functions>
        <Output>1*2, 3*4, 5*6
        -> Ans1 = 2
        -> Ans2 = 7
        -> Ans3 = 30
        </Output>
        <Results>
            <Result Value="2" />
            <Result Value="7" />
            <Result Value="30" />
        </Results>
    </Session>
</BreezyCalc>

In my application, the output is displayed in a textbox like this:

1*2, 3*4, 5*6
      -> Ans1 = 2
      -> Ans2 = 7
      -> Ans3 = 30

But when I load my session with an XmlReader, and I use ReadElementContentAsString() on the <Output> element, the output gets displayed in the textbox like this:

1*2, 3*4, 5*6      -> Ans1 = 2      -> Ans2 = 7      -> Ans3 = 30

When I copy that text from my application's textbox and paste it into Notepad, it looks the same, still all on one line. BUT, when I tried pasting it into StackOverflow's question submission textbox, it shows the line breaks correctly. So I am unsure whether this is caused by the XmlReader, or if it has to do with the textbox. I feel as though it may be the textbox, because like I said when I pasted it here the line breaks were there, but I just can't understand why the textbox won't display the line breaks.

Basically, I am asking what's the problem here? How can I read/write multi-line text from/to an XML file and preserve the line breaks?

4

0 に答える 0