Results 1 to 3 of 3

Thread: Open and Save XML file as utf8 encoding

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Location
    DC Metro area
    Posts
    53

    Open and Save XML file as utf8 encoding

    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.

  2. #2

    Thread Starter
    Member
    Join Date
    Feb 2010
    Location
    DC Metro area
    Posts
    53

    Question Re: Open and Save XML file as utf8 encoding

    Any ideas, I'm

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Open and Save XML file as utf8 encoding

    depends on the dash, where it is and what it's doing... but I doubt it has anything to do with UTF Encoding... 8, 16 or otherwise.

    Can you post the raw XML with the dash in it? Also... what's the error that is being reported?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width