Select the product you need help with
HOW TO: Use the Encoding Property with System.Xml Classes in Visual C# .NETArticle ID: 308061 - View products that this article applies to. This article was previously published under Q308061 On This PageThis article refers to the following Microsoft .NET
Framework Class Library namespace:
SUMMARY This step-by-step article explains how to use the Encoding property with XML in .NET Framework. The encoding declaration in
the XML declaration identifies the encoding format of the XML data. In the System.Xml namespace, the Encoding property of the classes identifies the encoding format.
The System.Xml namespace in .NET Framework includes the following classes that have the Encoding property:
The Encoding DeclarationSpecify the encoding declaration in the XML declaration section of the XML document. For example, the following declaration indicates that the document is in UTF-16 Unicode encoding format:For example, if you have the actual XML data in UTF-8 encoding format, but the encoding declaration is set to ISO-8859-1, you receive error messages similar to the following when you parse the document: There is invalid data at the root level. Line n,
position n. The following example shows how to set or get the encoding declaration of an XML document.
The Encoding Property of the ReadersThe XmlTextReader and the XmlValidatingReader classes provide a read-only Encoding property. These classes only read the encoding declaration value and do not determine the actual encoding format of the data.The following is a Visual C# .NET code sample that shows how to access the encoding attribute of an XML document. To run this sample, paste the following code in the try block of the previous code sample: REFERENCESFor more information about System.Xml and System.Text classes, refer to the following topics in the Microsoft .NET Framework SDK documentation:System.Xml Namespace For more information about character encoding, refer to the
following topic in the Microsoft Developer Network (MSDN) Library:
(http://msdn.microsoft.com/en-us/library/system.xml(VS.71).aspx)
System.Text Namespace
(http://msdn.microsoft.com/en-us/library/system.text(VS.71).aspx)
How to Encode XML Data For the latest XML download and information, refer to the
following MSDN Web site:
(http://msdn.microsoft.com/en-us/library/aa468560.aspx)
http://msdn.microsoft.com/xml
(http://msdn.microsoft.com/xml)
Properties | Article Translations
|


Back to the top








