XML zu XSD zu Datenklasse

  • VB.NET

Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von ErfinderDesRades.

    XML zu XSD zu Datenklasse

    Guten Abend an Alle!

    Ich habe folgendes Problem und weiß nicht wirklich, wie ich es am Besten codiere. Dazu kommt noch, dass ich mit XSD keine Erfahrung habe. Ich weiß nur, dass man aus einem XML-Schema (XSD) eine Datenklasse mit XSD.exe erzeugen kann.

    Ich habe folgende Aufgabenstellung:

    1) Es sollen XML Dateien (entsprechend einem bestimmten Aufbau) mit Daten an eine Plattform übertragen werden (Übertragung ist nicht wirklich das Problem)
    2) Als Respone bekommt man ebenfalls eine XML Datei mit bestimmten Aufbau und den Übertragungsdaten (Status, Fehlermeldung etc.)
    3) Als Doku gibt es nur den Aufbau der XML mit Datenfeldtyp und Länge und/oder Pflichtfeld als Excel Datei

    Meine Idee war diese XML Dateien mit einem Editor erstellen, dann Online daraus eine XSD erzeugen und aus dieser dann die Datenklasse für meine VB.NET Anwendung. Habe ich auch soweit gemacht (siehe Anhang), nur gefällt mir die Datenklasse nicht wirklich. Sie funktioniert zwar, aber irgendwie sieht das für mich nicht richtig codiert aus.

    Was ist eure Meinung dazu? Hat jemand so etwas schon einmal gemacht?

    Im Projekt sind im Ordner XML und XSD die ensprechenden Dateien vorhanden.

    Danke für eure Hinweise.
    Dateien
    Zu obiger Aufgabenstellung habe ich jetzt meine eigenen Datenklassen codiert.

    Datenklasse SetOrder:

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.ComponentModel
    2. Imports System.ComponentModel.DataAnnotations
    3. Imports System.Xml.Serialization
    4. Namespace SetData
    5. <Serializable>
    6. Public Class SetCustomer
    7. Private customersField As Customers
    8. <XmlElement(ElementName:="Customers")>
    9. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    10. Public Property Customers() As Customers
    11. Get
    12. Return Me.customersField
    13. End Get
    14. Set
    15. Me.customersField = Value
    16. End Set
    17. End Property
    18. End Class
    19. <Serializable>
    20. Public Class Customers
    21. Private customerListe As List(Of Customer)
    22. Public Sub New()
    23. customerListe = New List(Of Customer)
    24. End Sub
    25. Public Sub Add(pCustomer As Customer)
    26. customerListe.Add(pCustomer)
    27. End Sub
    28. <XmlElement(ElementName:="Customer")>
    29. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    30. Public Property CustomersListe() As List(Of Customer)
    31. Get
    32. Return Me.customerListe
    33. End Get
    34. Set
    35. Me.customerListe = Value
    36. End Set
    37. End Property
    38. End Class
    39. <Serializable>
    40. Public Class Customer
    41. Private requestIDField As String
    42. Private identifyNumberField As String
    43. Private keyAccountGroupField As String
    44. Private nameField As String
    45. Private name2Field As String
    46. Private addressField As String
    47. Private address2Field As String
    48. Private postalCodeField As String
    49. Private cityField As String
    50. Private countryField As String
    51. Private areaCodeField As String
    52. Private phoneField As String
    53. Private faxField As String
    54. Private emailField As String
    55. Private websiteField As String
    56. Private wasteProducerNumberField As String
    57. Private currencyCodeField As String
    58. Private taxNoField As String
    59. Private vATRegistrationNoField As String
    60. Private invoiceWithNoField As String
    61. '''<remarks/>
    62. <XmlElement(ElementName:="RequestID")>
    63. <MaxLength(50)>
    64. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    65. Public Property RequestID() As String
    66. Get
    67. Return Me.requestIDField
    68. End Get
    69. Set
    70. Me.requestIDField = Value
    71. End Set
    72. End Property
    73. '''<remarks/>
    74. <XmlElement(ElementName:="IdentifyNumber")>
    75. <MaxLength(15)>
    76. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    77. Public Property IdentifyNumber() As String
    78. Get
    79. Return Me.identifyNumberField
    80. End Get
    81. Set
    82. Me.identifyNumberField = Value
    83. End Set
    84. End Property
    85. '''<remarks/>
    86. <XmlElement(ElementName:="KeyAccountGroup")>
    87. <MaxLength(10)>
    88. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    89. Public Property KeyAccountGroup() As String
    90. Get
    91. Return Me.keyAccountGroupField
    92. End Get
    93. Set
    94. Me.keyAccountGroupField = Value
    95. End Set
    96. End Property
    97. '''<remarks/>
    98. <XmlElement(ElementName:="Name")>
    99. <MaxLength(30)>
    100. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    101. Public Property Name() As String
    102. Get
    103. Return Me.nameField
    104. End Get
    105. Set
    106. Me.nameField = Value
    107. End Set
    108. End Property
    109. '''<remarks/>
    110. <XmlElement(ElementName:="Name2")>
    111. <MaxLength(30)>
    112. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    113. Public Property Name2() As String
    114. Get
    115. Return Me.name2Field
    116. End Get
    117. Set
    118. Me.name2Field = Value
    119. End Set
    120. End Property
    121. '''<remarks/>
    122. <XmlElement(ElementName:="Address")>
    123. <MaxLength(30)>
    124. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    125. Public Property Address() As String
    126. Get
    127. Return Me.addressField
    128. End Get
    129. Set
    130. Me.addressField = Value
    131. End Set
    132. End Property
    133. '''<remarks/>
    134. <XmlElement(ElementName:="Address2")>
    135. <MaxLength(30)>
    136. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    137. Public Property Address2() As String
    138. Get
    139. Return Me.address2Field
    140. End Get
    141. Set
    142. Me.address2Field = Value
    143. End Set
    144. End Property
    145. '''<remarks/>
    146. <XmlElement(ElementName:="PostalCode")>
    147. <MaxLength(20)>
    148. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    149. Public Property PostalCode() As String
    150. Get
    151. Return Me.postalCodeField
    152. End Get
    153. Set
    154. Me.postalCodeField = Value
    155. End Set
    156. End Property
    157. '''<remarks/>
    158. <XmlElement(ElementName:="City")>
    159. <MaxLength(30)>
    160. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    161. Public Property City() As String
    162. Get
    163. Return Me.cityField
    164. End Get
    165. Set
    166. Me.cityField = Value
    167. End Set
    168. End Property
    169. '''<remarks/>
    170. <XmlElement(ElementName:="Country")>
    171. <MaxLength(10)>
    172. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    173. Public Property Country() As String
    174. Get
    175. Return Me.countryField
    176. End Get
    177. Set
    178. Me.countryField = Value
    179. End Set
    180. End Property
    181. '''<remarks/>
    182. <XmlElement(ElementName:="AreaCode")>
    183. <MaxLength(10)>
    184. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    185. Public Property AreaCode() As String
    186. Get
    187. Return Me.areaCodeField
    188. End Get
    189. Set
    190. Me.areaCodeField = Value
    191. End Set
    192. End Property
    193. '''<remarks/>
    194. <XmlElement(ElementName:="Phone")>
    195. <MaxLength(30)>
    196. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    197. Public Property Phone() As String
    198. Get
    199. Return Me.phoneField
    200. End Get
    201. Set
    202. Me.phoneField = Value
    203. End Set
    204. End Property
    205. '''<remarks/>
    206. <XmlElement(ElementName:="Fax")>
    207. <MaxLength(30)>
    208. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    209. Public Property Fax() As String
    210. Get
    211. Return Me.faxField
    212. End Get
    213. Set
    214. Me.faxField = Value
    215. End Set
    216. End Property
    217. '''<remarks/>
    218. <XmlElement(ElementName:="Email")>
    219. <MaxLength(80)>
    220. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    221. Public Property Email() As String
    222. Get
    223. Return Me.emailField
    224. End Get
    225. Set
    226. Me.emailField = Value
    227. End Set
    228. End Property
    229. '''<remarks/>
    230. <XmlElement(ElementName:="Website")>
    231. <MaxLength(80)>
    232. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    233. Public Property Website() As String
    234. Get
    235. Return Me.websiteField
    236. End Get
    237. Set
    238. Me.websiteField = Value
    239. End Set
    240. End Property
    241. '''<remarks/>
    242. <XmlElement(ElementName:="WasteProducerNumber")>
    243. <MaxLength(10)>
    244. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    245. Public Property WasteProducerNumber() As String
    246. Get
    247. Return Me.wasteProducerNumberField
    248. End Get
    249. Set
    250. Me.wasteProducerNumberField = Value
    251. End Set
    252. End Property
    253. '''<remarks/>
    254. <XmlElement(ElementName:="CurrencyCode")>
    255. <MaxLength(10)>
    256. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    257. Public Property CurrencyCode() As String
    258. Get
    259. Return Me.currencyCodeField
    260. End Get
    261. Set
    262. Me.currencyCodeField = Value
    263. End Set
    264. End Property
    265. '''<remarks/>
    266. <XmlElement(ElementName:="TaxNo")>
    267. <MaxLength(20)>
    268. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    269. Public Property TaxNo() As String
    270. Get
    271. Return Me.taxNoField
    272. End Get
    273. Set
    274. Me.taxNoField = Value
    275. End Set
    276. End Property
    277. '''<remarks/>
    278. <XmlElement(ElementName:="VATRegistrationNo")>
    279. <MaxLength(20)>
    280. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    281. Public Property VATRegistrationNo() As String
    282. Get
    283. Return Me.vATRegistrationNoField
    284. End Get
    285. Set
    286. Me.vATRegistrationNoField = Value
    287. End Set
    288. End Property
    289. '''<remarks/>
    290. <XmlElement(ElementName:="InvoiceWithNo")>
    291. <MaxLength(20)>
    292. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    293. Public Property InvoiceWithNo() As String
    294. Get
    295. Return Me.invoiceWithNoField
    296. End Get
    297. Set
    298. Me.invoiceWithNoField = Value
    299. End Set
    300. End Property
    301. End Class
    302. End Namespace



    und im Programmcode verwende ich diese Datenklasse so

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Dim mSetCustomer As New SetData.SetCustomer
    2. Dim mCustomers As New SetData.Customers
    3. Dim mCustomer As New SetData.Customer
    4. ' 1.Eintrag
    5. With mCustomer
    6. .Name = "Wenzl Gerhard"
    7. .Address = "Nr. 115"
    8. .AreaCode = "2"
    9. .City = "Hannersdorf"
    10. .PostalCode = "7477"
    11. .CurrencyCode = "EUR"
    12. .Email = "gerhard@wenzl.co.at"
    13. .Phone = "+43 660 3368902"
    14. .Website = "www.wenzl.co.at"
    15. End With
    16. mCustomers.Add(mCustomer)
    17. ' 2.Eintrag
    18. mCustomer = New SetData.Customer
    19. With mCustomer
    20. .Name = "MIS Software GmbH"
    21. .Address = "Siezenheimerstraße 23"
    22. .AreaCode = "2"
    23. .City = "Salzburg"
    24. .PostalCode = "8020"
    25. .CurrencyCode = "EUR"
    26. .Email = "office@mis-software.de"
    27. .Phone = "+49 677 3377902"
    28. .Website = "www.mis-software.de"
    29. End With
    30. mCustomers.Add(mCustomer)
    31. mSetCustomer.Customers = mCustomers
    32. Dim serializer As New XmlSerializer(GetType(SetData.SetCustomer))
    33. Dim writer As New StreamWriter(Application.StartupPath + "\Export\SetCustomer.xml")
    34. serializer.Serialize(writer, mSetCustomer)
    35. writer.Close()



    das Ergebnis sieht dann so aus, wie ich es brauche

    Spoiler anzeigen

    XML-Quellcode

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <SetCustomer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    3. <Customers>
    4. <Customer>
    5. <Name>Wenzl Gerhard</Name>
    6. <Address>Nr. 115</Address>
    7. <PostalCode>7477</PostalCode>
    8. <City>Hannersdorf</City>
    9. <AreaCode>2</AreaCode>
    10. <Phone>+43 660 3368902</Phone>
    11. <Email>[email=gerhard@wenzl.co.at]gerhard@wenzl.co.at[/email]</Email>
    12. <Website>[url]www.wenzl.co.at[/url]</Website>
    13. <CurrencyCode>EUR</CurrencyCode>
    14. </Customer>
    15. <Customer>
    16. <Name>MIS Software GmbH</Name>
    17. <Address>Siezenheimerstraße 23</Address>
    18. <PostalCode>8020</PostalCode>
    19. <City>Salzburg</City>
    20. <AreaCode>2</AreaCode>
    21. <Phone>+43 660 3368902</Phone>
    22. <Email>[email=office@mis-software.de]office@mis-software.de[/email]</Email>
    23. <Website>[url]www.mis-software.de[/url]</Website>
    24. <CurrencyCode>EUR</CurrencyCode>
    25. </Customer>
    26. </Customers>
    27. </SetCustomer>



    Vielleicht interessiert es jemanden oder es braucht jemand eine Idee...

    Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „GerhardW“ ()

    Leider funktionieren meine Datenmodelle doch noch nicht ganz sauber.
    Als XML Response erhalte ich folgende Struktur

    Spoiler anzeigen

    XML-Quellcode

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <SetResponse>
    3. <Responses>
    4. <Response>
    5. <RequestID>1234534</RequestID>
    6. <TicketID>0994343</TicketID>
    7. <StatusID>45</StatusID>
    8. <StatusDescription>Da ist ein Fehler aufgetreten</StatusDescription>
    9. <ErrorInfo>Testerror</ErrorInfo>
    10. <EnwisID>xxxx</EnwisID>
    11. </Response>
    12. <Response>
    13. <RequestID>23243</RequestID>
    14. <TicketID>000003</TicketID>
    15. <StatusID>45</StatusID>
    16. <ErrorInfo>Testerror</ErrorInfo>
    17. <EnwisID>yyyyy</EnwisID>
    18. <ConfirmationID>ABCDEF1234</ConfirmationID>
    19. </Response>
    20. <Response>
    21. <RequestID>223232323</RequestID>
    22. <StatusID>45</StatusID>
    23. <StatusDescription>Testfehler</StatusDescription>
    24. <ErrorInfo>Testerror</ErrorInfo>
    25. <EnwisID>zzzzzz</EnwisID>
    26. <ConfirmationID>ID0045455</ConfirmationID>
    27. </Response>
    28. </Responses>
    29. </SetResponse>



    Welche ich in mein DatenModell einlese (was ja auch funktioniert):

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.ComponentModel
    2. Imports System.ComponentModel.DataAnnotations
    3. Imports System.Xml.Serialization
    4. Namespace ResponseData
    5. <Serializable>
    6. Public Class SetResponse
    7. Private responseField As Responses
    8. <XmlElement(ElementName:="Responses")>
    9. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    10. Public Property Responses() As Responses
    11. Get
    12. Return Me.responseField
    13. End Get
    14. Set
    15. Me.responseField = Value
    16. End Set
    17. End Property
    18. End Class
    19. <Serializable>
    20. Public Class Responses
    21. Private responseListe As List(Of Response)
    22. Public Sub New()
    23. responseListe = New List(Of Response)
    24. End Sub
    25. Public Sub Add(pResponse As Response)
    26. responseListe.Add(pResponse)
    27. End Sub
    28. <XmlElement(ElementName:="Response")>
    29. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    30. Public Property ResponsesListe() As List(Of Response)
    31. Get
    32. Return Me.responseListe
    33. End Get
    34. Set
    35. Me.responseListe = Value
    36. End Set
    37. End Property
    38. End Class
    39. <Serializable>
    40. Public Class Response
    41. Private requestIDField As String
    42. Private ticketIDField As String
    43. Private statusIDField As Integer
    44. Private statusDescriptionField As String
    45. Private errorInfoField As String
    46. Private enwisIDField As String
    47. Private confirmationIDField As String
    48. Public Sub New()
    49. requestIDField = ""
    50. ticketIDField = ""
    51. statusIDField = 0
    52. statusDescriptionField = ""
    53. errorInfoField = ""
    54. enwisIDField = ""
    55. confirmationIDField = ""
    56. End Sub
    57. '''<remarks/>
    58. <XmlElement(ElementName:="RequestID")>
    59. <MaxLength(50)>
    60. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    61. Public Property RequestID() As String
    62. Get
    63. Return Me.requestIDField
    64. End Get
    65. Set
    66. Me.requestIDField = Value
    67. End Set
    68. End Property
    69. '''<remarks/>
    70. <XmlElement(ElementName:="TicketID")>
    71. <MaxLength(20)>
    72. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    73. Public Property TicketID() As String
    74. Get
    75. Return Me.ticketIDField
    76. End Get
    77. Set
    78. Me.ticketIDField = Value
    79. End Set
    80. End Property
    81. '''<remarks/>
    82. <XmlElement(ElementName:="StatusID")>
    83. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    84. Public Property StatusID() As Integer
    85. Get
    86. Return Me.statusIDField
    87. End Get
    88. Set
    89. Me.statusIDField = Value
    90. End Set
    91. End Property
    92. '''<remarks/>
    93. <XmlElement(ElementName:="StatusDescription")>
    94. <MaxLength(200)>
    95. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    96. Public Property StatusDescription() As String
    97. Get
    98. Return Me.statusDescriptionField
    99. End Get
    100. Set
    101. Me.statusDescriptionField = Value
    102. End Set
    103. End Property
    104. '''<remarks/>
    105. <XmlElement(ElementName:="ErrorInfo")>
    106. <MaxLength(1024)>
    107. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    108. Public Property ErrorInfo() As String
    109. Get
    110. Return Me.errorInfoField
    111. End Get
    112. Set
    113. Me.errorInfoField = Value
    114. End Set
    115. End Property
    116. '''<remarks/>
    117. <XmlElement(ElementName:="EnwisID")>
    118. <MaxLength(20)>
    119. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    120. Public Property EnwisID() As String
    121. Get
    122. Return Me.enwisIDField
    123. End Get
    124. Set
    125. Me.enwisIDField = Value
    126. End Set
    127. End Property
    128. '''<remarks/>
    129. <XmlElement(ElementName:="ConfirmationID")>
    130. <MaxLength(5)>
    131. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    132. Public Property ConfirmationID() As String
    133. Get
    134. Return Me.confirmationIDField
    135. End Get
    136. Set
    137. Me.confirmationIDField = Value
    138. End Set
    139. End Property
    140. End Class
    141. End Namespace



    es gibt nur einen kleinen Schönheitsfehler und der ist im Anhang ersichtlich.

    Mein DataModel hat folgende Struktur: Responses - ResponsesListe - Response

    Ich möchte aber: Responses - Response (Auflistung so wie in der Resonse XML Datei)

    Kann mir da bitte jemand weiterhelfen? Ich weiß nicht wie ich das codieren soll bzw. komme ich nicht zu meinem gewünschtem Ergebnis.
    Bilder
    • DataModel.png

      127,75 kB, 1.515×357, 129 mal angesehen
    Schmeiss die Klasse Responses weg.
    Die hat nichts, was eine List(Of Response) nicht auch schon hätte.
    SetResponse verändert sich dadurch zu:

    VB.NET-Quellcode

    1. <Serializable>
    2. Public Class SetResponse
    3. Private responseField As New List(Of Response) 'New ist wichtig!
    4. <XmlElement(ElementName:="Responses")>
    5. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    6. Public Property Responses() As Responses
    7. Get
    8. Return Me.responseField
    9. End Get
    10. Set
    11. Me.responseField = Value
    12. End Set
    13. End Property
    14. End Class

    noch besser wäre:

    VB.NET-Quellcode

    1. <Serializable>
    2. Public Class SetResponse
    3. Private responseField As New List(Of Response) 'New ist wichtig!
    4. <XmlElement(ElementName:="Responses")>
    5. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    6. Public Readonly Property Responses() As Responses
    7. Get
    8. Return Me.responseField
    9. End Get
    10. End Property
    11. End Class
    @ErfinderDesRades

    habe es jetzt geändert, die Struktur passt aber es werden keine Daten eingelesen (siehe Anhang). Ich denke das habe ich schon einmal versucht. Irgendwie hab ich da einen Knopf im Kopf ;)

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.ComponentModel
    2. Imports System.ComponentModel.DataAnnotations
    3. Imports System.Xml.Serialization
    4. Namespace ResponseData
    5. <Serializable>
    6. Public Class SetResponse
    7. Private responseField As New List(Of Response)
    8. <XmlElement(ElementName:="Responses")>
    9. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    10. Public ReadOnly Property Responses() As List(Of Response)
    11. Get
    12. Return Me.responseField
    13. End Get
    14. End Property
    15. End Class
    16. '<Serializable>
    17. 'Public Class Responses
    18. ' Private responseListe As List(Of Response)
    19. ' Public Sub New()
    20. ' responseListe = New List(Of Response)
    21. ' End Sub
    22. ' Public Sub Add(pResponse As Response)
    23. ' responseListe.Add(pResponse)
    24. ' End Sub
    25. ' <XmlElement(ElementName:="Response")>
    26. ' <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    27. ' Public Property ResponsesListe() As List(Of Response)
    28. ' Get
    29. ' Return Me.responseListe
    30. ' End Get
    31. ' Set
    32. ' Me.responseListe = Value
    33. ' End Set
    34. ' End Property
    35. 'End Class
    36. <Serializable>
    37. Public Class Response
    38. Private requestIDField As String
    39. Private ticketIDField As String
    40. Private statusIDField As Integer
    41. Private statusDescriptionField As String
    42. Private errorInfoField As String
    43. Private enwisIDField As String
    44. Private confirmationIDField As String
    45. Public Sub New()
    46. requestIDField = ""
    47. ticketIDField = ""
    48. statusIDField = 0
    49. statusDescriptionField = ""
    50. errorInfoField = ""
    51. enwisIDField = ""
    52. confirmationIDField = ""
    53. End Sub
    54. '''<remarks/>
    55. <XmlElement(ElementName:="RequestID")>
    56. <MaxLength(50)>
    57. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    58. Public Property RequestID() As String
    59. Get
    60. Return Me.requestIDField
    61. End Get
    62. Set
    63. Me.requestIDField = Value
    64. End Set
    65. End Property
    66. '''<remarks/>
    67. <XmlElement(ElementName:="TicketID")>
    68. <MaxLength(20)>
    69. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    70. Public Property TicketID() As String
    71. Get
    72. Return Me.ticketIDField
    73. End Get
    74. Set
    75. Me.ticketIDField = Value
    76. End Set
    77. End Property
    78. '''<remarks/>
    79. <XmlElement(ElementName:="StatusID")>
    80. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    81. Public Property StatusID() As Integer
    82. Get
    83. Return Me.statusIDField
    84. End Get
    85. Set
    86. Me.statusIDField = Value
    87. End Set
    88. End Property
    89. '''<remarks/>
    90. <XmlElement(ElementName:="StatusDescription")>
    91. <MaxLength(200)>
    92. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    93. Public Property StatusDescription() As String
    94. Get
    95. Return Me.statusDescriptionField
    96. End Get
    97. Set
    98. Me.statusDescriptionField = Value
    99. End Set
    100. End Property
    101. '''<remarks/>
    102. <XmlElement(ElementName:="ErrorInfo")>
    103. <MaxLength(1024)>
    104. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    105. Public Property ErrorInfo() As String
    106. Get
    107. Return Me.errorInfoField
    108. End Get
    109. Set
    110. Me.errorInfoField = Value
    111. End Set
    112. End Property
    113. '''<remarks/>
    114. <XmlElement(ElementName:="EnwisID")>
    115. <MaxLength(20)>
    116. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    117. Public Property EnwisID() As String
    118. Get
    119. Return Me.enwisIDField
    120. End Get
    121. Set
    122. Me.enwisIDField = Value
    123. End Set
    124. End Property
    125. '''<remarks/>
    126. <XmlElement(ElementName:="ConfirmationID")>
    127. <MaxLength(5)>
    128. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)>
    129. Public Property ConfirmationID() As String
    130. Get
    131. Return Me.confirmationIDField
    132. End Get
    133. Set
    134. Me.confirmationIDField = Value
    135. End Set
    136. End Property
    137. End Class
    138. End Namespace


    Einlesen tue ich so...

    VB.NET-Quellcode

    1. Private Sub btnImport_Click(sender As Object, e As EventArgs) Handles btnImport.Click
    2. Dim mSetResponse As ResponseData.SetResponse = New ResponseData.SetResponse
    3. Dim serializer As New XmlSerializer(GetType(ResponseData.SetResponse ))
    4. Dim reader As New IO.StreamReader(Application.StartupPath + "\Export\SetResponse.xml")
    5. mSetResponse = CType(serializer.Deserialize(reader), ResponseData.SetResponse)
    6. reader.Close()
    7. reader.Dispose()
    8. End Sub


    Edit: Im Anhang auch mein Testprojekt mit XML Dateien
    Edit 2: Ich habe deinen Code bei

    VB.NET-Quellcode

    1. Public ReadOnly Property Responses() As Responses

    auf

    VB.NET-Quellcode

    1. Public ReadOnly Property Responses() As List(Of Response)

    geändert. Weil da stimmt doch der Typ nicht?
    Bilder
    • DataModel-Neu01.png

      172,98 kB, 1.535×515, 131 mal angesehen
    Dateien
    • RLG-Test.zip

      (734,26 kB, 131 mal heruntergeladen, zuletzt: )

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „GerhardW“ ()

    @ErfinderDesRades

    Ich habe es lösen können.

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.ComponentModel
    2. Imports System.ComponentModel.DataAnnotations
    3. Imports System.Xml.Serialization
    4. Namespace ResponseData
    5. <Serializable>
    6. Partial Public Class SetResponse
    7. Private responseField As List(Of Response)
    8. <XmlArrayItem("Response", IsNullable:=False)>
    9. Public Property Responses() As List(Of Response)
    10. Get
    11. Return Me.responseField
    12. End Get
    13. Set
    14. Me.responseField = Value
    15. End Set
    16. End Property
    17. End Class
    18. <Serializable>
    19. Partial Public Class Response
    20. Private requestIDField As String
    21. Private ticketIDField As String
    22. Private statusIDField As Integer
    23. usw.


    Hier muss auch ein

    Quellcode

    1. Set
    rein und das Property muss als

    Quellcode

    1. <XmlArrayItem("Response", IsNullable:=False)>
    gekennzeichnet sein

    VB.NET-Quellcode

    1. <XmlArrayItem("Response", IsNullable:=False)>
    2. Public Property Responses() As List(Of Response)
    3. Get
    4. Return Me.responseField
    5. End Get
    6. Set
    7. Me.responseField = Value
    8. End Set
    9. End Property


    Danke nochmals für die BasisKlasse...

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „GerhardW“ ()