I am Trying to export xml from some data in C#
XDocument doc = XDocument.Parse(xml);
After I save the XML, I found that the XML contains
<?xml version="1.0" encoding="utf-8"?>
Which i did not enter at all, and cause problem like following.
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="..\..\dco.xsl"?>
<S>
<B>
</B>
</S>
I dont want the first row to appear, any ideas?
Thanks for your respond.
What you are saying is “AFTER” you parse with the string as you see above your result contains duplicate declarations?
Now i am not sure how you are saving your response but here is a sample application which produces similar results.
Produces the result:
Which is the problem you have. You need to remove the xml declaration before saving. This can be done by using an xml writer when saving your xml output. Here is the sample application with an extension method to write the new document without the declaration.