我使用以下方法从xml反序列化对象数据。变量 exportExclusions 是使用正确数量的子对象创建的,但它们都具有空值属性。
Public Sub LoadExportExclusionsFromXMLFile()
Try
Dim settings As XmlReaderSettings = New XmlReaderSettings()
settings.DtdProcessing = DtdProcessing.Parse
exportExclusions = New ExportExclusions()
Dim reader = XmlReader.Create("../../../ExportExclusions.xml", settings)
Dim serializer = New System.Xml.Serialization.XmlSerializer(exportExclusions.GetType())
exportExclusions = DirectCast(serializer.Deserialize(reader), ExportExclusions)
reader.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
这是xml文件
<?xml version="1.0" encoding="utf-8" ?>
<ExportExclusions>
<!--Schema Begin-->
<xs:schema id="ExportExclusions" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Attributes -->
<xs:attribute name="Name" type="xs:string" />
<xs:attribute name="FullyQualifiedName" type="xs:string" />
<xs:attribute name="Export" type="xs:boolean"/>
<!--Attribute Groups-->
<xs:attributeGroup name="Exportable">
<xs:attribute ref="Name" use ="required"/>
<xs:attribute ref="Export" use ="required"/>
</xs:attributeGroup>
<xs:attributeGroup name="ExportableClass">
<xs:attribute ref="FullyQualifiedName" use="optional"/>
<xs:attributeGroup ref="Exportable"/>
</xs:attributeGroup>
<!-- Elements -->
<xs:element name="Property">
<xs:complexType>
<xs:attributeGroup ref="Exportable"/>
</xs:complexType>
</xs:element>
<xs:element name="Member">
<xs:complexType>
<xs:attributeGroup ref="Exportable"/>
</xs:complexType>
</xs:element>
<xs:element name="Members">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="Member" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Properties">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="Property" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ClassExclusion">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="Properties" minOccurs="0" maxOccurs="1"/>
<xs:element ref="Members" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attributeGroup ref="ExportableClass"/>
</xs:complexType>
</xs:element>
<xs:element name="ClassExclusions">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="1">
<xs:element ref="ClassExclusion" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GlobalExclusions">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element ref="Properties" minOccurs="0" maxOccurs="1"/>
<xs:element ref="Members" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ExportExclusions">
<xs:complexType>
<xs:sequence>
<xs:element ref="GlobalExclusions" minOccurs="0" maxOccurs="1"/>
<xs:element ref="ClassExclusions" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<!--Schema End-->
<!--Data Begin-->
<GlobalExclusions>
<Properties>
<Property Name="CurrentPathGid" Export="false"/>
<Property Name="AllowChanges" Export="false"/>
<Property Name="CanRaiseChangeEvents" Export="false"/>
<Property Name="CanRaiseEvents" Export="false"/>
<Property Name="Changed" Export="false"/>
<Property Name="Delete" Export="false"/>
<Property Name="Deleted" Export="false"/>
<Property Name="Expired" Export="false"/>
<Property Name="FormControlsAreLoaded" Export="false"/>
<Property Name="HasFormControls" Export="false"/>
<Property Name="IdInstance" Export="false"/>
<Property Name="IsDeleted" Export="false"/>
<Property Name="isNewAction" Export="false"/>
<Property Name="IsPopupWindowsLoaded" Export="false"/>
<Property Name="Loaded" Export="false"/>
<Property Name="LoadedTime" Export="false"/>
<Property Name="Modified" Export="false"/>
<Property Name="Nuevo" Export="false"/>
<Property Name="ObjectTypeId" Export="false"/>
<Property Name="ObjectTypeLid" Export="false"/>
<Property Name="SavedVersionId" Export="false"/>
<Property Name="Saving" Export="false"/>
<Property Name="SourceIsLoaded" Export="false"/>
<Property Name="SuspendDeleteIndex" Export="false"/>
<Property Name="TypeId" Export="false"/>
</Properties>
<Members/>
</GlobalExclusions>
<ClassExclusions>
<ClassExclusion Name="X" FullyQualifiedName="XYZ" Export="true">
<Properties>
<Property Name="Length" Export="false"/>
<Property Name="Value" Export="false"/>
</Properties>
<Members/>
</ClassExclusion>
<ClassExclusion Name="X1" FullyQualifiedName="XYZ1" Export="true">
<Properties>
<Property Name="LocationToClient" Export="false"/>
<Property Name="DataSnapshotId" Export="false"/>
</Properties>
<Members/>
</ClassExclusion>
<ClassExclusion Name="X2" FullyQualifiedName="XYZ2" Export="true">
<Properties>
<Property Name="Parent" Export="false"/>
</Properties>
<Members/>
</ClassExclusion>
<ClassExclusion Name="X3" FullyQualifiedName="XYZ3" Export="true">
<Properties>
<Property Name="Text" Export="false"/>
<Property Name="Upgraded" Export="false"/>
<Property Name="LoadedTime" Export="false"/>
<Property Name="Id" Export="false"/>
<Property Name="WorkingSection" Export="false"/>
</Properties>
<Members>
<Member Name="ObjectTypeId" Export="false" />
</Members>
</ClassExclusion>
</ClassExclusions>
<!--Data End-->
</ExportExclusions>