I'm adding an XDeclaration to my Xdocument as follows:
XDocument xml = new XDocument(new XDeclaration("1.0", "utf-8", "yes")
This gives me the result:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
I'm building XML for Quickbooks Merchant Services so I only need:
<?xml version="1.0"?>
Is it possible to do this?
You can try using custom StringWriter which doesn't provide any encoding, for example :
public class StringWriterNoEncoding : StringWriter
{
public override Encoding Encoding
{
get { return null; }
}
}
Then use StringWriterNoEncoding to print the XML :
XDocument xdoc = new XDocument(new XDeclaration("1.0", "", ""), new XElement("Root"));
var sw = new StringWriterNoEncoding();
xdoc.Save(sw);
Console.WriteLine(sw.ToString());
//above will print :
//<?xml version="1.0"?>
//<Root />
Set encoding and standalone to null:
XDocument xml = new XDocument(new XDeclaration("1.0", null, null)
will give
<?xml version="1.0"?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With