Friday 14 January 2011

Non white space characters cannot be added to content.

When trying to initialise an XDocument with a string containing XML, I kept getting the error:

Unhandled Exception: System.ArgumentException: Non white space characters cannot be added to content.

With help from a colleague, and recalling how I'd got around this error previously, the solution is to use the static XDocument.Parse( string ) method. Eg:

var myXDoc = XDocument.Parse( xmlString );