Erick Erick - 4 months ago 48
ASP.NET (C#) Question

Xdocument does not print declaration

I try to use the API and to do I need to use XML.

Currently I have an error saying "apiProtocol is not found" I guess then that my Xml document is malformed.

The Current xml sent is :

<apiProtocol version="1" xmlns:xsi="" xsi:noNameSpaceSchemaLocation="checkrequest.xsd">
<checkRequest user="ifuzion" password="fish4gold121" reference="123456789">
<domain name="" />

Apparently the
part does not print out.

My code is basically something similar to :

XDocument xDocument = new XDocument(
new XDeclaration("1.0", "UTF-8", "yes"),
new XElement("Books"));

(I stripped my code for a question of simplicity but the structure is exactly similar).

Is there any reason why XDocument doesn't print out the
part ? It seems that with XmlDocument it works but not with XDocument ... any hints ?


How are you printing out the contents of your XDocument?

The .ToString() method does not include the xml header, but the .Save() method does.

Edit: The same answer was given here.