asyncwait
asyncwait

Reputation: 4537

Preserving whitespaces and line-breaks in XML Document

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 ?

Upvotes: 1

Views: 1439

Answers (1)

bobince
bobince

Reputation: 536715

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.

Upvotes: 3

Related Questions