I have following XElement:
<title>
<bold>Foo</bold>
<italic>Bar</italic>
</title>
When I get Value
property it returns FooBar
without space. How to fix it?
By definition, the Value
of the <title>
element is the concatenation of all text in this element. By default whitespace between elements and their contents is ignored, so it gives "FooBar". You can specify that you want to preserve whitespace:
var element = XElement.Parse(xml, LoadOptions.PreserveWhitespace);
However it will preserve all whitespace, including the line feeds and indentation. In your XML, there is a line feed and two spaces between "Foo" and "Bar"; how is it supposed to guess that you only want to keep one space?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With