我正在尝试在vb.net 2008中对xml文件进行反序列化的简单示例,但某处肯定会出现一个简单的错误。
错误:
There is an error in XML document (1, 2).
xml文件:
<Item>test</Item>
vb代码:
Public Class xmlClass
Public Item As String
End Class
...并且在表格类中:
Private Sub Deserialize()
Dim serializer As New XmlSerializer(GetType(xmlClass))
Dim reader As New FileStream("c:\tmp\tmp2.xml", FileMode.Open)
Dim xi As xmlClass
xi = CType(serializer.Deserialize(reader), xmlClass)
End Sub
答案 0 :(得分:3)
尝试:
<xmlClass>
<Item>Test</Item>
</xmlClass>
您需要将class元素放在字段值周围。我在VS 2012上使用您的上述代码确认了这一点。
答案 1 :(得分:0)
尝试反序列化此文件:
<?xml version="1.0" encoding="utf-8"?>
<Item>test</Item>