【发布时间】:2014-09-20 07:55:56
【问题描述】:
假设我有一个包含患者信息的 XML 文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfPatient xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Patient>
<firstName>Vince</firstName>
<lastName>Smith</lastName>
<dateOfBirth>05/05/1912</dateOfBirth>
<phone>3056988877</phone>
<email>random@google.com</email>
<insurance>Humana</insurance>
<typeOfPlan>PPA</typeOfPlan>
<subID>123456</subID>
<planID>654321</planID>
</Patient>
<Patient>
<firstName>Mark</firstName>
<lastName>Jones</lastName>
<dateOfBirth>05/05/1992</dateOfBirth>
<phone>3058877457</phone>
<email>random@hotmail.com</email>
<insurance>PlanB</insurance>
<typeOfPlan>PPO</typeOfPlan>
<subID>987987</subID>
<planID>987987</planID>
</Patient>
如何将该信息加载到 Visual Studios 中的患者列表中?这是我的尝试,但出现错误:
Dim Patients As New List(Of Patient)
Dim p As New Patient
Dim reader As New StreamReader("..\..\patients.xml")
Dim serial As New XmlSerializer(GetType(List(Of Patient)))
For Each paciente In serial.Deserialize(reader)
Patients.Add(paciente)
Next
但是它给我一个未处理的表达式错误。
患者类仅具有 XML 中所有字段的所有属性。
【问题讨论】:
-
异常的信息是什么?
-
并且:除了完整的消息文本:这是编译器错误吗?还是运行时错误?如果是运行时:确保您还包括内部异常的消息 - 一直到内部异常为空。
标签: .net deserialization xml-deserialization