0

I use the following method to deserialize the objects data from xml. The variable exportExclusions got created with the right number of child objects but all of them have null value properties.

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

and here is the xml file

<?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>
Ebeid ElSayed
  • 1,126
  • 2
  • 15
  • 32
  • so, your saying you created the class object and gave values to the public fields or properties, serialized it, deserialized and have empty property values - right? – OneFineDay Apr 13 '15 at 15:09
  • Your example seems to have values in it. Can you point out what is not getting populated? – OneFineDay Apr 13 '15 at 15:56
  • @OneFineDay someone created the file to me.I generated the classes from it using xsd.exe tool. Then try to load the values from the file into .net objects. Objects get created but no data loaded into the objects' properties. – Ebeid ElSayed Apr 13 '15 at 16:26
  • Then you problem lies with the person who sent you the file. There is nothing we can do to help you deserialize data that does not exist. – OneFineDay Apr 13 '15 at 16:28

0 Answers0