Change XMLDocument Encoding

Posted on 2006-05-25
Last Modified: 2008-01-09
I've loaded the xml below into an XMLDocument (call it XmlDoc).

Is there a way to programmatically change the encoding attribute value to "utf-8" (or whatever),
OTHER than doing a string replace on the innerText of the XMLDocumentDeclaration?

<?xml version="1.0" encoding="utf-16" ?>
Question by:codequest
    1 Comment
    LVL 2

    Accepted Solution

    Well, there's this, but it uses the replace function

    Public Sub ConvertEncoding(ByRef vXDoc As XmlDocument, ByVal vCode As String)
         Dim wN1 As XmlNode = vXDoc.CreateNode(XmlNodeType.Element, "ss", "xxx")
         wN1 = varXDoc.FirstChild
         wN1.InnerText = Replace(wN1.InnerText, "utf-16", varCode)
         wN1.InnerText = Replace(wkN1.InnerText, "utf-8", varCode)
    End Sub

    I was hoping there might be some method that could get at the encoding as an element of the DOM.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now