views:

297

answers:

1

I have an xml document like this,

<Customer ID = "000A551"
          Name = "Robert"
          Salaried = "yes"
          Area = "VA" 
          />

Please note the how attributes are line-breaked and white-spaced for the editing and reading convenience. When using XDocument or XmlDocument to modify this document whole formatting goes away. Looks like PreserveWhitespace will only handle significant whitespace.

Is there any way out there to maintain line-breaks and whitespaces ?

+2  A: 

No, not handling XML natively. The ‘infoset’ (the data model of XML) does not maintain any record of attribute order or whitespace inside an attribute list. Some XML processors maintain attribute order as a side-effect, but none store whitespace between attributes. It is extremely unusual for anyone to care.

bobince
Also, it's very dangerous to rely on XML processor side-effects.
Robert Rossney