xml error: Non white space characters cannot be added to content

It looks like you’re attempting to load an XML file into an XDocument, but to do so you need to call XDocument.Load("C:\\temp\\contacts.xml"); – you can’t pass an XML file into the constructor.

You can also load a string of XML with XDocument.Parse(stringXml);.

Change your first line to:

var doc = XDocument.Load("c:\\temp\\contacts.xml");

And it will work.

For reference, there are 4 overloads of the XDocument constructor:

XDocument();
XDocument(Object[]);
XDocument(XDocument);
XDocument(XDeclaration, Object[]);

You might have been thinking of the third one (XDocument(XDocument)), but to use that one you’d have to write:

var doc = new XDocument(XDocument.Load("c:\\temp\\contacts.xml"));

Which would be redundant when var doc = XDocument.Load("c:\\temp\\contacts.xml"); will suffice.

See XDocument Constructor for the gritty details.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)