Question How to Deserialize???

raysefo

Well-known member
Joined
Jul 21, 2010
Messages
207
Programming Experience
Beginner
Hi,

I m not familiar with XML so i hope you can help me. There is a XML schema which was inside of a wsdl. I used xsd.exe tool of VS.Net 2010 and generated class from it. But the problem is i could NOT manage to deserialize this XML document as follows:

p1 becomes NULL.

sample code:
...
Dim s1 As New StreamReader("D:\Odds.xml")
Dim p1 As New DataSetLiveOdds()
Dim x1 As New XmlSerializer(p1.GetType, xRoot)
p1 = x1.Deserialize(s1)----> NULL
s1.Close()

Here is the schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="DataSet">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="Outcome">
<xs:sequence>
<xs:element name="outcomeDescription" nillable="true" type="xs:string"/>
<xs:element name="outcomeId" nillable="true" type="xs:string"/>
<xs:element name="outcomeOdd" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfOutcome">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="item" type="Outcome"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Event">
<xs:sequence>
<xs:element name="eventDescription" nillable="true" type="xs:string"/>
<xs:element name="eventId" nillable="true" type="xs:string"/>
<xs:element name="eventStatus" nillable="true" type="xs:string"/>
<xs:element name="outcomeArray" nillable="true" type="ArrayOfOutcome"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfEvent">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="item" type="Event"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="DataSetLiveOdds">
<xs:complexContent>
<xs:extension base="DataSet">
<xs:sequence>
<xs:element name="eventArray" nillable="true" type="ArrayOfEvent"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>

Here is class generated from schema via xsd.exe:

'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.1
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On

Imports System.Xml.Serialization

'
'This source code was auto-generated by xsd, Version=4.0.30319.1.
'

'''<remarks/>

Partial Public Class forwardLiveOdds

Private dsSetLiveOddsField As DataSetLiveOdds

Private sDrawNumberField As String

Private sOddsRevisionField As String

'''<remarks/>
Public Property dsSetLiveOdds() As DataSetLiveOdds
Get
Return Me.dsSetLiveOddsField
End Get
Set(ByVal value As DataSetLiveOdds)
Me.dsSetLiveOddsField = value
End Set
End Property

'''<remarks/>
Public Property sDrawNumber() As String
Get
Return Me.sDrawNumberField
End Get
Set(ByVal value As String)
Me.sDrawNumberField = value
End Set
End Property

'''<remarks/>
Public Property sOddsRevision() As String
Get
Return Me.sOddsRevisionField
End Get
Set(ByVal value As String)
Me.sOddsRevisionField = value
End Set
End Property
End Class

'''<remarks/>

Partial Public Class DataSetLiveOdds
Inherits DataSet

Private eventArrayField() As [Event]

'''<remarks/>
<System.Xml.Serialization.XmlArrayAttribute(IsNullable:=True), _
System.Xml.Serialization.XmlArrayItemAttribute("item", IsNullable:=False)> _
Public Property eventArray() As [Event]()
Get
Return Me.eventArrayField
End Get
Set(ByVal value As [Event]())
Me.eventArrayField = value
End Set
End Property
End Class

'''<remarks/>

Partial Public Class [Event]

Private eventDescriptionField As String

Private eventIdField As String

Private eventStatusField As String

Private outcomeArrayField() As Outcome

'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=True)> _
Public Property eventDescription() As String
Get
Return Me.eventDescriptionField
End Get
Set(ByVal value As String)
Me.eventDescriptionField = value
End Set
End Property

'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=True)> _
Public Property eventId() As String
Get
Return Me.eventIdField
End Get
Set(ByVal value As String)
Me.eventIdField = value
End Set
End Property

'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=True)> _
Public Property eventStatus() As String
Get
Return Me.eventStatusField
End Get
Set(ByVal value As String)
Me.eventStatusField = value
End Set
End Property

'''<remarks/>

Public Property outcomeArray() As Outcome()
Get
Return Me.outcomeArrayField
End Get
Set(ByVal value As Outcome())
Me.outcomeArrayField = value
End Set
End Property
End Class

'''<remarks/>

Partial Public Class Outcome

Private outcomeDescriptionField As String

Private outcomeIdField As String

Private outcomeOddField As String

'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=True)> _
Public Property outcomeDescription() As String
Get
Return Me.outcomeDescriptionField
End Get
Set(ByVal value As String)
Me.outcomeDescriptionField = value
End Set
End Property

'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=True)> _
Public Property outcomeId() As String
Get
Return Me.outcomeIdField
End Get
Set(ByVal value As String)
Me.outcomeIdField = value
End Set
End Property

'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=True)> _
Public Property outcomeOdd() As String
Get
Return Me.outcomeOddField
End Get
Set(ByVal value As String)
Me.outcomeOddField = value
End Set
End Property
End Class

'''<remarks/>

Partial Public Class DataSet
End Class

'''<remarks/>

Partial Public Class forwardLiveOddsResponse

Private forwardLiveOddsReturnField As String

'''<remarks/>
Public Property forwardLiveOddsReturn() As String
Get
Return Me.forwardLiveOddsReturnField
End Get
Set(ByVal value As String)
Me.forwardLiveOddsReturnField = value
End Set
End Property
End Class
 
I have a very similar setup I'm trying to work on and yet some of the XML text element do not deserialize to the object. For instance, outcomeOdd property of the object will have Nothing as its value but forwardLiveOddsReturn will have its value. Any ideas as to why this might happen? I can't find anything on the interwebz or the forumz.. but I'm going to keep looking.
 
Back
Top