locked
XmlDocument.LoadXml throws Invalid Character Error RRS feed

  • Question

  • VS 2008 Professional in VB. 

    Dim xmlDoc as XmlDocument = ......
    Dim xmlHttp As New MSXML2.ServerXMLHTTP
    Dim xmlResponse As New XmlDocument

    xmlHttp.send(xmlDoc)
    xmlResponse.LoadXml(xmlHttp.responseText)

    Error on last line is 'hexadecimal value 0xFFFF, is an invalid character.'  The offending character is a question mark not 0xFFFF.  How do I trap this and replace the bad character with space?  I' tried:

    xmlHttp.responseText.Replace(

    "?", Space(1))


    ebassador
    "Find it, fix it, move on."
    Monday, December 13, 2010 5:55 PM

Answers

  • I found a way to get around this error by cleansing the string of all unwanted characters:

    dim SafeXML String = str 

    For Each c In str

        Select Case True

            Case (c = vbCr Or c = vbLf Or c = Space(1))

                ' These are OK

            Case (c < Chr(33) Or c > Chr(126))

                safeXML = safeXML.Replace(c, Space(1))

        End Select

    Next

     


    ebassador
    "Find it, fix it, move on."

     

    • Marked as answer by ebassador Monday, December 13, 2010 8:03 PM
    Monday, December 13, 2010 7:44 PM