XDeclaration::Encoding Property
Gets or sets the encoding for this document.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
Any value returned by WebName is a valid value.
If you read an encoded document, then this property will be set to the code page name.
If you set this property to a valid code page name, then when serializing, LINQ to XML will serialize with the specified encoding.
The following example creates two documents, one with utf-8 encoding, and one with utf-16 encoding. It then loads the documents and prints the encoding to the console.
This example produces the following output:
Creating a document with utf-8 encoding Encoding is:utf-8 Creating a document with utf-16 encoding Encoding is:utf-16 Encoded document: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Root>Content</Root> Encoding of loaded document is:utf-8 Encoded document: <?xml version="1.0" encoding="utf-16" standalone="yes"?> <Root>Content</Root> Encoding of loaded document is:utf-16
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1