Change XMLDocument Encoding

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" ?>
<Control>
      <Value1>
            <SubVal1A>Units</SubVal1A>
            <SubVal1B>Type</SubVal1B>      
      </Value1>
      <Value2>
            <SubVal2A>Over</SubVal2A>
            <SubVal2B>Load</SubVal2B>
      </Value2>
</Control>
LVL 2
codequestAsked:
Who is Participating?
 
codequestAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.