Erick Erick - 1 month ago 6
ASP.NET (C#) Question

Xdocument does not print declaration

I try to use the domainpeople.com 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="http://www.w3.org/2001/XMLSchema-instance" xsi:noNameSpaceSchemaLocation="checkrequest.xsd">
<checkRequest user="ifuzion" password="fish4gold121" reference="123456789">
<domain name="google.com" />
</checkRequest>
</apiProtocol>


Apparently the
<?xml?>
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
<?xml?>
part ? It seems that with XmlDocument it works but not with XDocument ... any hints ?

Answer

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.