views:

64

answers:

2

Im reading from a xml and my values seem to come all right except with \n\t\t wrapping them... presumably something to do with spacing and stuff... how do i tell C# to ignore this?

+1  A: 

Did you try to call the Trim method on the returned string? That should strip off line feeds, tabs and spaces from the start and end of the string.

Fredrik Mörk
+1  A: 

I'm assuming that your XML looks something like this:

<foo>
    <bar>
        baz
    </bar>
</foo>

While that may look pretty for a person, the XML parser is required to preserve all whitespace. Nor is the parser permitted to combine whitespace that appears on either side of an element (so in this case the DOM representation of foo has three children: a Text node containing only whitespace, an Element node for bar, and another Text node containing only whitespace).

Bottom line is that Fredrik's answer is the correct one, but I figured that the rationale behind the behavior was important.

kdgregory