Mit dieser Methode kann das Encoding eines XmlDocument geändert werden.
Bsp:
aus <xml version="1.0" encoding="utf-16"?>
wird <xml version="1.0" encoding="utf-8"?>
Benötigte Namespaces:
System.Xml;
/// <summary>
/// Changes the XML encoding.
/// </summary>
/// <param name="xmlDoc">The XmlDocument.</param>
/// <param name="newEncoding">The new encoding.</param>
/// <returns></returns>
private XmlDocument ChangeXmlEncoding(XmlDocument xmlDoc, string newEncoding)
{
if (xmlDoc.FirstChild.NodeType == XmlNodeType.XmlDeclaration)
{
XmlDeclaration xmlDeclaration = (XmlDeclaration)xmlDoc.FirstChild;
xmlDeclaration.Encoding = newEncoding;
}
return xmlDoc;
}
Kommentare zum Snippet