我尝试编写一个小程序,将数据从SQL数据库导出到XML(然后再将相同的数据导入另一个数据库)。
为此,我得到了相关表的模式,从表中读取所有数据,并将其放入一个XML结构中,以便在处理完所有表后进行保存。
我用
XDocument
作为XML结构。
Dim result As XDocument
Dim element As XElement
Dim item As XElement
result = New XDocument(New XDeclaration("1.0", "utf-8", "yes"))
element = New XElement("table", New XAttribute("name", <variable holding the table name>))
result.Add(element)
item = New XElement("item")
element.Add(item)
item.Add(New XAttribute(<variable holding the column name>, <variable holding the column data>))
...
到目前为止,还不错。
甚至似乎在刻意掩饰特殊人物(所以我想)。
但是现在我得到一个错误,因为我要导出的字符串列的值包含无效字符(
ChrW(1)
). 在添加
XAttribute
ToString
.
经过数小时的数据检查,我发现哪个表和哪个数据项包含无效字符,但是我如何屏蔽它们才能将它们导出到XML?有没有内置的方法,或者我必须自己编写?