I have been working on a project that opens, modifies, then saves an xml file. The problem is that one of the attribute values contains a dash, causing the parser to throw an error when my xml editor application attempts to open the file. I have yet to find a working solution after weeks of searching the web, I tried the the following method for saving the xml file:

Code:
    Public Sub save_xml_UTF8(ByVal xmlFile As XmlDocument)

        Dim sw As TextWriter = New StreamWriter(LoadFile(), False, Encoding.UTF8)

        Using sw
            xmlFile.Save(sw)
        End Using

    End Sub
The parser still throws an error at the dash character in the xml file. So is this really saving the xml document in UTF8 encoding? FYI...The xml document is already formed, so I don't need to create the xml document from scratch, the encoding tag is already present at the beginning of the document.

Also, I haven't figured out how to create a xmldocument object with UTF8 encoding when loading the file path. See the following:

Code:
' This is how I was loading the file into the xmlDocument object.  No encoding assumed, will default to UTF16.  I need it to be UTF8 encoded.

Dim m_xmld As XmlDocument
                m_xmld = New XmlDocument
                Dim strfilepath As String = LoadFile()
                m_xmld.Load(strfilepath)
Any help is greatly appreciated. Thanks.