0

I am receiving this error:

' ', hexadecimal value 0x19, is an invalid character

when serializing a DataTable as XML, then deserializing this XML back to a DataTable.

This is something that has been working for months now, any ideas how this character is now all of a sudden finding its way into the XML in question?

Working in VB.NET. Here is the code that does the work.

Public Function ConvertDataTableToXML(ByVal tbl As DataTable) As String
    tbl.TableName = "gv"
    Dim writer As New System.IO.StringWriter()
    tbl.WriteXml(writer, XmlWriteMode.WriteSchema, False)
    Return writer.ToString()
End Function

Public Function ConvertXMLToDataTable(ByVal xml As String) As DataTable
    Dim tbl As New DataTable
    Dim xmlReader As XmlReader = xmlReader.Create(New StringReader(xml))
    tbl.ReadXml(xmlReader)
    Return tbl
End Function 'This function throws the error.

I've tried to strip invalid characters out using regex expressions also but I am still receiving the error when the table tries to read the XML

TopBanana9000
  • 818
  • 2
  • 14
  • 32
  • a) What language are you working in. b) How is the XML generated? that would be the place to start looking for the character. – Tim Apr 13 '16 at 20:14
  • I've edited my question to answer yours – TopBanana9000 Apr 13 '16 at 20:16
  • I'd expect the error is due to data in the DataTable. If the table isn't too big, you might check it to see if you can find the offending character. These kinds of issues can be hard to run down IME. – Tim Apr 13 '16 at 20:19
  • 1
    Possible duplicate of [XMLTextReader is created but XslCompiledTransform.Transform fails with invalid character](http://stackoverflow.com/questions/28282249/xmltextreader-is-created-but-xslcompiledtransform-transform-fails-with-invalid-c) – GSerg Apr 13 '16 at 20:42
  • It is a minus sign which is not a valid xml character. See : https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=wiki%20xml%20html%20special%20characters – jdweng Apr 13 '16 at 21:10

1 Answers1

0

Per the W3C XML Recommendation, these characters are legal in XML:

Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]

0x19 is unicode END OF MEDIUM and is not in the allowed set.

kjhughes
  • 106,133
  • 27
  • 181
  • 240