views:

77

answers:

1

I need to know how the XML class for the serialization should look like:

I need this XML

<?xml version="1.0" encoding="UTF-8"?>
<import date="2010-02-12T23:33:39">
  <T_Employee>
    <MI_KZ>HKBZV</MI_KZ>
    <MI_Name>John</MI_Name>
    <MI_Vorname>Doe</MI_Vorname>
    <MI_Nummer>987654321</MI_Nummer>
    <MI_DatumVon>2010-02-11T10:45:37</MI_DatumVon>
        <MI_DatumBis>2010-03-13T00:00:00</MI_DatumBis>
    <AP_Bezeichnung>5-B-03</AP_Bezeichnung>
    <KOE_Code>FHBM</KOE_Code>
    <KST_Code></KST_Code>
    <KST_Kurz><![CDATA[]]></KST_Kurz>
      </T_Employee>
  <T_Employee>
    <MI_KZ>EX2FC</MI_KZ>
    <MI_Name>Doe</MI_Name>
    <MI_Vorname>Johnny</MI_Vorname>
    <MI_Nummer>123456789</MI_Nummer>
    <MI_DatumVon>2010-01-13T05:52:16</MI_DatumVon>
    <MI_DatumBis>2010-02-01T23:00:00</MI_DatumBis>
    <AP_Bezeichnung>Test1</AP_Bezeichnung>
    <KOE_Code>Test2</KOE_Code>
    <KST_Code>Test3</KST_Code>
    <KST_Kurz>Test4</KST_Kurz>
  </T_Employee>

</import>

But so far, I got that

<?xml version="1.0" encoding="utf-8"?>
<import date="2010-02-12T23:33:39">
  <T_Employee>
    <cEmployee>
      <MI_KZ />
      <MI_Name>Doe</MI_Name>
          <MI_Vorname>John</MI_Vorname>
      <MI_Nummer />
      <MI_DatumVon />
      <MI_DatumBis />
      <AP_Bezeichnung />
      <KOE_Code>abc</KOE_Code>
      <KST_Code />
      <KST_Kurz />
    </cEmployee>
    <cEmployee>
      <MI_KZ />
      <MI_Name>Doe</MI_Name>
      <MI_Vorname>Johnny</MI_Vorname>
      <MI_Nummer />
      <MI_DatumVon />
      <MI_DatumBis />
      <AP_Bezeichnung />
      <KOE_Code>def</KOE_Code>
      <KST_Code />
      <KST_Kurz />
    </cEmployee>
  </T_Employee>
</import>

using this VB.NET class

 Public Class cEmployee
    <System.Xml.Serialization.XmlElement("MI_KZ")> _
    Public strMI_KZ As String = ""

    <System.Xml.Serialization.XmlElement("MI_Name")> _
    Public strMI_Name As String = ""

    <System.Xml.Serialization.XmlElement("MI_Vorname")> _
    Public strMI_Vorname As String = ""

    <System.Xml.Serialization.XmlElement("MI_Nummer")> _
    Public strMI_Nummer As String = ""

    <System.Xml.Serialization.XmlElement("MI_DatumVon")> _
    Public strMI_DatumVon As String = ""

    <System.Xml.Serialization.XmlElement("MI_DatumBis")> _
    Public strMI_DatumBis As String = ""

    <System.Xml.Serialization.XmlElement("AP_Bezeichnung")> _
    Public strAP_Bezeichnung As String = ""

    <System.Xml.Serialization.XmlElement("KOE_Code")> _
    Public strKOE_Code As String = ""

    <System.Xml.Serialization.XmlElement("KST_Code")> _
    Public strKST_Code As String = ""

    <System.Xml.Serialization.XmlElement("KST_Kurz")> _
    Public strKST_Kurz As String = ""
End Class


<System.Xml.Serialization.XmlRoot("import")> _
Public Class cImportXML
    <System.Xml.Serialization.XmlAttribute("date")> _
    Public generated As String = ""



    <System.Xml.Serialization.XmlArray("T_Employee")> _
    Public Mitarbeiter As List(Of cEmployee) = New List(Of cEmployee)

End Class
+3  A: 

One trick here is xsd.exe:

xsd.exe sample.xml
xsd.exe sample.xsd /classes /language:VB

This should generate compatible classes for you. However, the specific problem in this case is that you want [XmlElement], not [XmlArray]:

<System.Xml.Serialization.XmlElementAttribute("T_Employee")> _
Public HelsanaMitarbeiter As List(Of cEmployee) = New List(Of cEmployee)
Marc Gravell