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.
XDocument doc = XDocument.Parse("<?xml-stylesheet type=\"text/xsl\" href=\"dco.xsl\"?><S><B></B></S>");
doc.Save(Console.OpenStandardOutput());
Produces the result:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="dco.xsl"?>
<S>
<B></B>
</S>
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.
class Program
{
static void Main(string[] args)
{
XDocument doc = XDocument.Parse("<?xml-stylesheet type=\"text/xsl\" href=\"dco.xsl\"?><S><B></B></S>");
doc.SaveWithoutDeclaration(Console.OpenStandardOutput());
Console.ReadKey();
}
}
internal static class Extensions
{
public static void SaveWithoutDeclaration(this XDocument doc, string FileName)
{
using(var fs = new StreamWriter(FileName))
{
fs.Write(doc.ToString());
}
}
public static void SaveWithoutDeclaration(this XDocument doc, Stream Stream)
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(doc.ToString());
Stream.Write(bytes, 0, bytes.Length);
}
}