Connecting Tech Pros Worldwide Forums | Help | Site Map

Deserializing an array

Wayne Wengert
Guest
 
Posts: n/a
#1: Nov 12 '05
Using VB.NET I want to read in an XML file that has an array of objects and
then step through the resulting array in code. I build a class to define the
structure and I am running code to read in the data but I can't figure out
where the data is in the resulting array. Most of the relevant code is
below. When I run the code to desrialize I get no errors but if I try to
look at some of the data via the command window I get errors such as this:

?judges2.Judges(0).JudgeFirstName

Index '0' for dimension '0' is out of range.



What am I missing here?



Wayne



================= Execution Code =======================

Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnImport.Click

ReadJudgesTable("c:\2005 WGI\WGI Tabulation Program\Data
Files\data\JudgesTable.xml")

End Sub

Protected Sub ReadJudgesTable(ByVal filename As String)

Dim ser As New XmlSerializer(GetType(ArrayOfJudgeTableEntity))

' Read In the Judges table

Dim fs2 As New FileStream(filename, FileMode.Open)

' Deserialize into another instance of ArrayOfJudgeTableEntity

Dim judges2 As ArrayOfJudgeTableEntity = CType(ser.Deserialize(fs2),
ArrayOfJudgeTableEntity)

fs2.Close()

MsgBox("JudgesTable has been deserialized - I hope",
MsgBoxStyle.Exclamation, "Got Judges")

End Sub

================================================== ==

================== Class Definition ==================

Imports System.Xml

Imports System.Xml.Serialization

Imports System.Collections

Public Class ArrayOfJudgeTableEntity

<XmlArray("JudgeTableEntity"), XmlArrayItem("Judge", IsNullable:=True)> _

Public Judges() As Judge


Public Sub New()

End Sub 'New

'Public Sub New(ByVal id As String, ByVal fn As String, ByVal ln As String,
ByVal type As String)

' JudgeID = id

' JudgeFirstName = fn

' JudgeFirstName = ln

' JudgeType = type

'End Sub 'New

End Class 'ArrayOfJudgeTableEntity

Public Class Judge

Public JudgeID As String

Public JudgeFirstName As String

Public JudgeLastName As String

Public JudgeType As String

Public Sub New()

End Sub 'New

Public Sub New(ByVal id As String, ByVal fn As String, ByVal ln As String,
ByVal type As String)

JudgeID = id

JudgeType = type

JudgeFirstName = fn

JudgeLastName = ln

End Sub 'New

End Class 'Judge

====================================



=========== Sample XML Data ================

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfJudgeTableEntity xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<JudgeTableEntity>
<JudgeId>63371991-cdf9-4cc5-99c1-a42c599498f8</JudgeId>
<JudgeFirstName>Kristen</JudgeFirstName>
<JudgeLastName>O'Melia</JudgeLastName>
<JudgeType>Equipment</JudgeType>
</JudgeTableEntity>
<JudgeTableEntity>
<JudgeId>ce2c0c6e-4094-43da-9d8c-9726d81b017e</JudgeId>
<JudgeFirstName>Smith</JudgeFirstName>
<JudgeLastName>Dan</JudgeLastName>
<JudgeType>Movement</JudgeType>
</JudgeTableEntity>
<JudgeTableEntity>
<JudgeId>efe977f6-04ec-4a65-ae46-34b0f75de87f</JudgeId>
<JudgeFirstName>Kathy</JudgeFirstName>
<JudgeLastName>Whitcomb</JudgeLastName>
<JudgeType>Ensemble Color Guard</JudgeType>
</JudgeTableEntity>
<JudgeTableEntity>
<JudgeId>99d92f77-39e1-46b8-b9e2-446b8cea1b0c</JudgeId>
<JudgeFirstName>Shirlee</JudgeFirstName>
<JudgeLastName>Whitcomb</JudgeLastName>
<JudgeType>General Effect Color Guard</JudgeType>
</JudgeTableEntity>
<JudgeTableEntity>
<JudgeId>f7ae92ef-9bb2-48fe-bbe8-3c566b924d0f</JudgeId>
<JudgeFirstName>George</JudgeFirstName>
<JudgeLastName>Oliviero</JudgeLastName>
<JudgeType>General Effect Color Guard</JudgeType>
</JudgeTableEntity>
<JudgeTableEntity>
<JudgeId>5e1cad18-4ef9-4625-99c2-ee12c2b05cda</JudgeId>
<JudgeFirstName>Lee</JudgeFirstName>
<JudgeLastName>Carpenter</JudgeLastName>
<JudgeType>Penalty</JudgeType>
</JudgeTableEntity>
</ArrayOfJudgeTableEntity>

==========================================



Christoph Schittko [MVP]
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Deserializing an array



Wayne,

It's hard to tell what's going on without seeing code and/or XML. I have
a tutorial on serializing and deserializing arrays at [0]. Take a look
and feel free to post back if you have additional questions.

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko
[color=blue]
> -----Original Message-----
> From: Wayne Wengert [mailto:wayneDONTWANTSPAM@wengert.com]
> Posted At: Monday, January 24, 2005 5:25 AM
> Posted To: microsoft.public.dotnet.xml
> Conversation: Deserializing an array
> Subject: Deserializing an array
>
> Using VB.NET I want to read in an XML file that has an array of[/color]
objects[color=blue]
> and
> then step through the resulting array in code. I build a class to[/color]
define[color=blue]
> the
> structure and I am running code to read in the data but I can't figure[/color]
out[color=blue]
> where the data is in the resulting array. Most of the relevant code is
> below. When I run the code to desrialize I get no errors but if I try[/color]
to[color=blue]
> look at some of the data via the command window I get errors such as[/color]
this:[color=blue]
>
> ?judges2.Judges(0).JudgeFirstName
>
> Index '0' for dimension '0' is out of range.
>
>
>
> What am I missing here?
>
>
>
> Wayne
>
>
>
> ================= Execution Code =======================
>
> Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnImport.Click
>
> ReadJudgesTable("c:\2005 WGI\WGI Tabulation Program\Data
> Files\data\JudgesTable.xml")
>
> End Sub
>
> Protected Sub ReadJudgesTable(ByVal filename As String)
>
> Dim ser As New XmlSerializer(GetType(ArrayOfJudgeTableEntity))
>
> ' Read In the Judges table
>
> Dim fs2 As New FileStream(filename, FileMode.Open)
>
> ' Deserialize into another instance of ArrayOfJudgeTableEntity
>
> Dim judges2 As ArrayOfJudgeTableEntity = CType(ser.Deserialize(fs2),
> ArrayOfJudgeTableEntity)
>
> fs2.Close()
>
> MsgBox("JudgesTable has been deserialized - I hope",
> MsgBoxStyle.Exclamation, "Got Judges")
>
> End Sub
>
> ================================================== ==
>
> ================== Class Definition ==================
>
> Imports System.Xml
>
> Imports System.Xml.Serialization
>
> Imports System.Collections
>
> Public Class ArrayOfJudgeTableEntity
>
> <XmlArray("JudgeTableEntity"), XmlArrayItem("Judge",[/color]
IsNullable:=True)> _[color=blue]
>
> Public Judges() As Judge
>
>
> Public Sub New()
>
> End Sub 'New
>
> 'Public Sub New(ByVal id As String, ByVal fn As String, ByVal ln As
> String,
> ByVal type As String)
>
> ' JudgeID = id
>
> ' JudgeFirstName = fn
>
> ' JudgeFirstName = ln
>
> ' JudgeType = type
>
> 'End Sub 'New
>
> End Class 'ArrayOfJudgeTableEntity
>
> Public Class Judge
>
> Public JudgeID As String
>
> Public JudgeFirstName As String
>
> Public JudgeLastName As String
>
> Public JudgeType As String
>
> Public Sub New()
>
> End Sub 'New
>
> Public Sub New(ByVal id As String, ByVal fn As String, ByVal ln As[/color]
String,[color=blue]
> ByVal type As String)
>
> JudgeID = id
>
> JudgeType = type
>
> JudgeFirstName = fn
>
> JudgeLastName = ln
>
> End Sub 'New
>
> End Class 'Judge
>
> ====================================
>
>
>
> =========== Sample XML Data ================
>
> <?xml version="1.0" encoding="utf-8"?>
> <ArrayOfJudgeTableEntity xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <JudgeTableEntity>
> <JudgeId>63371991-cdf9-4cc5-99c1-a42c599498f8</JudgeId>
> <JudgeFirstName>Kristen</JudgeFirstName>
> <JudgeLastName>O'Melia</JudgeLastName>
> <JudgeType>Equipment</JudgeType>
> </JudgeTableEntity>
> <JudgeTableEntity>
> <JudgeId>ce2c0c6e-4094-43da-9d8c-9726d81b017e</JudgeId>
> <JudgeFirstName>Smith</JudgeFirstName>
> <JudgeLastName>Dan</JudgeLastName>
> <JudgeType>Movement</JudgeType>
> </JudgeTableEntity>
> <JudgeTableEntity>
> <JudgeId>efe977f6-04ec-4a65-ae46-34b0f75de87f</JudgeId>
> <JudgeFirstName>Kathy</JudgeFirstName>
> <JudgeLastName>Whitcomb</JudgeLastName>
> <JudgeType>Ensemble Color Guard</JudgeType>
> </JudgeTableEntity>
> <JudgeTableEntity>
> <JudgeId>99d92f77-39e1-46b8-b9e2-446b8cea1b0c</JudgeId>
> <JudgeFirstName>Shirlee</JudgeFirstName>
> <JudgeLastName>Whitcomb</JudgeLastName>
> <JudgeType>General Effect Color Guard</JudgeType>
> </JudgeTableEntity>
> <JudgeTableEntity>
> <JudgeId>f7ae92ef-9bb2-48fe-bbe8-3c566b924d0f</JudgeId>
> <JudgeFirstName>George</JudgeFirstName>
> <JudgeLastName>Oliviero</JudgeLastName>
> <JudgeType>General Effect Color Guard</JudgeType>
> </JudgeTableEntity>
> <JudgeTableEntity>
> <JudgeId>5e1cad18-4ef9-4625-99c2-ee12c2b05cda</JudgeId>
> <JudgeFirstName>Lee</JudgeFirstName>
> <JudgeLastName>Carpenter</JudgeLastName>
> <JudgeType>Penalty</JudgeType>
> </JudgeTableEntity>
> </ArrayOfJudgeTableEntity>
>
> ==========================================[/color]


Wayne Wengert
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Deserializing an array


Christoph;

The code and XML was included in the post. I went to your web site but did
not find the tutorial you mentioned. Exactly where is it?

Wayne

"Christoph Schittko [MVP]" <INVALIDEMAIL@austin.rr.com> wrote in message
news:eiZk9c1AFHA.3376@TK2MSFTNGP12.phx.gbl...[color=blue]
>
> Wayne,
>
> It's hard to tell what's going on without seeing code and/or XML. I have
> a tutorial on serializing and deserializing arrays at [0]. Take a look
> and feel free to post back if you have additional questions.
>
> HTH,
> Christoph Schittko
> MVP XML
> http://weblogs.asp.net/cschittko
>[color=green]
> > -----Original Message-----
> > From: Wayne Wengert [mailto:wayneDONTWANTSPAM@wengert.com]
> > Posted At: Monday, January 24, 2005 5:25 AM
> > Posted To: microsoft.public.dotnet.xml
> > Conversation: Deserializing an array
> > Subject: Deserializing an array
> >
> > Using VB.NET I want to read in an XML file that has an array of[/color]
> objects[color=green]
> > and
> > then step through the resulting array in code. I build a class to[/color]
> define[color=green]
> > the
> > structure and I am running code to read in the data but I can't figure[/color]
> out[color=green]
> > where the data is in the resulting array. Most of the relevant code is
> > below. When I run the code to desrialize I get no errors but if I try[/color]
> to[color=green]
> > look at some of the data via the command window I get errors such as[/color]
> this:[color=green]
> >
> > ?judges2.Judges(0).JudgeFirstName
> >
> > Index '0' for dimension '0' is out of range.
> >
> >
> >
> > What am I missing here?
> >
> >
> >
> > Wayne
> >
> >
> >
> > ================= Execution Code =======================
> >
> > Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles btnImport.Click
> >
> > ReadJudgesTable("c:\2005 WGI\WGI Tabulation Program\Data
> > Files\data\JudgesTable.xml")
> >
> > End Sub
> >
> > Protected Sub ReadJudgesTable(ByVal filename As String)
> >
> > Dim ser As New XmlSerializer(GetType(ArrayOfJudgeTableEntity))
> >
> > ' Read In the Judges table
> >
> > Dim fs2 As New FileStream(filename, FileMode.Open)
> >
> > ' Deserialize into another instance of ArrayOfJudgeTableEntity
> >
> > Dim judges2 As ArrayOfJudgeTableEntity = CType(ser.Deserialize(fs2),
> > ArrayOfJudgeTableEntity)
> >
> > fs2.Close()
> >
> > MsgBox("JudgesTable has been deserialized - I hope",
> > MsgBoxStyle.Exclamation, "Got Judges")
> >
> > End Sub
> >
> > ================================================== ==
> >
> > ================== Class Definition ==================
> >
> > Imports System.Xml
> >
> > Imports System.Xml.Serialization
> >
> > Imports System.Collections
> >
> > Public Class ArrayOfJudgeTableEntity
> >
> > <XmlArray("JudgeTableEntity"), XmlArrayItem("Judge",[/color]
> IsNullable:=True)> _[color=green]
> >
> > Public Judges() As Judge
> >
> >
> > Public Sub New()
> >
> > End Sub 'New
> >
> > 'Public Sub New(ByVal id As String, ByVal fn As String, ByVal ln As
> > String,
> > ByVal type As String)
> >
> > ' JudgeID = id
> >
> > ' JudgeFirstName = fn
> >
> > ' JudgeFirstName = ln
> >
> > ' JudgeType = type
> >
> > 'End Sub 'New
> >
> > End Class 'ArrayOfJudgeTableEntity
> >
> > Public Class Judge
> >
> > Public JudgeID As String
> >
> > Public JudgeFirstName As String
> >
> > Public JudgeLastName As String
> >
> > Public JudgeType As String
> >
> > Public Sub New()
> >
> > End Sub 'New
> >
> > Public Sub New(ByVal id As String, ByVal fn As String, ByVal ln As[/color]
> String,[color=green]
> > ByVal type As String)
> >
> > JudgeID = id
> >
> > JudgeType = type
> >
> > JudgeFirstName = fn
> >
> > JudgeLastName = ln
> >
> > End Sub 'New
> >
> > End Class 'Judge
> >
> > ====================================
> >
> >
> >
> > =========== Sample XML Data ================
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <ArrayOfJudgeTableEntity xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> > <JudgeTableEntity>
> > <JudgeId>63371991-cdf9-4cc5-99c1-a42c599498f8</JudgeId>
> > <JudgeFirstName>Kristen</JudgeFirstName>
> > <JudgeLastName>O'Melia</JudgeLastName>
> > <JudgeType>Equipment</JudgeType>
> > </JudgeTableEntity>
> > <JudgeTableEntity>
> > <JudgeId>ce2c0c6e-4094-43da-9d8c-9726d81b017e</JudgeId>
> > <JudgeFirstName>Smith</JudgeFirstName>
> > <JudgeLastName>Dan</JudgeLastName>
> > <JudgeType>Movement</JudgeType>
> > </JudgeTableEntity>
> > <JudgeTableEntity>
> > <JudgeId>efe977f6-04ec-4a65-ae46-34b0f75de87f</JudgeId>
> > <JudgeFirstName>Kathy</JudgeFirstName>
> > <JudgeLastName>Whitcomb</JudgeLastName>
> > <JudgeType>Ensemble Color Guard</JudgeType>
> > </JudgeTableEntity>
> > <JudgeTableEntity>
> > <JudgeId>99d92f77-39e1-46b8-b9e2-446b8cea1b0c</JudgeId>
> > <JudgeFirstName>Shirlee</JudgeFirstName>
> > <JudgeLastName>Whitcomb</JudgeLastName>
> > <JudgeType>General Effect Color Guard</JudgeType>
> > </JudgeTableEntity>
> > <JudgeTableEntity>
> > <JudgeId>f7ae92ef-9bb2-48fe-bbe8-3c566b924d0f</JudgeId>
> > <JudgeFirstName>George</JudgeFirstName>
> > <JudgeLastName>Oliviero</JudgeLastName>
> > <JudgeType>General Effect Color Guard</JudgeType>
> > </JudgeTableEntity>
> > <JudgeTableEntity>
> > <JudgeId>5e1cad18-4ef9-4625-99c2-ee12c2b05cda</JudgeId>
> > <JudgeFirstName>Lee</JudgeFirstName>
> > <JudgeLastName>Carpenter</JudgeLastName>
> > <JudgeType>Penalty</JudgeType>
> > </JudgeTableEntity>
> > </ArrayOfJudgeTableEntity>
> >
> > ==========================================[/color]
>
>[/color]


Christoph Schittko [MVP]
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Deserializing an array



I'm sorry, I didn't scroll down far enough last night to find the XML
AND I didn't paste the link ... bad christoph

The link I meant to include was:

http://www.topxml.com/xmlserializer/...on_classes.asp.

Looking at your classes though, this class definition would match

<XmlArray("JudgeTableEntity"), XmlArrayItem("Judge", IsNullable:=True)>
_

Public Judges() As Judge


This XML:

<JudgeTableEntity>
<Judge>
....
</Judge>
<Judge>
....
</Judge>
</JudgeTableEntity>

Because you declare the class to map to XML with an enclosing XmlArray
item <JudgeTableEntity> for array item elements <Judge>.

In the example XML you posted though, there is no enclosing element
around the array items. Instead, the array items are JudgeTableEntity
elements.

Change the class definition to:

<XmlElement("JudgeTableEntity", IsNullable:=True)> _
Public Judges() As Judge

And you should be good to go.

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

[color=blue]
> -----Original Message-----
> From: Wayne Wengert [mailto:wayneDONTWANTSPAM@wengert.com]
> Posted At: Wednesday, January 26, 2005 3:28 PM
> Posted To: microsoft.public.dotnet.xml
> Conversation: Deserializing an array
> Subject: Re: Deserializing an array
>
> Christoph;
>
> The code and XML was included in the post. I went to your web site but[/color]
did[color=blue]
> not find the tutorial you mentioned. Exactly where is it?
>
> Wayne
>
> "Christoph Schittko [MVP]" <INVALIDEMAIL@austin.rr.com> wrote in[/color]
message[color=blue]
> news:eiZk9c1AFHA.3376@TK2MSFTNGP12.phx.gbl...[color=green]
> >
> > Wayne,
> >
> > It's hard to tell what's going on without seeing code and/or XML. I[/color][/color]
have[color=blue][color=green]
> > a tutorial on serializing and deserializing arrays at [0]. Take a[/color][/color]
look[color=blue][color=green]
> > and feel free to post back if you have additional questions.
> >
> > HTH,
> > Christoph Schittko
> > MVP XML
> > http://weblogs.asp.net/cschittko
> >[color=darkred]
> > > -----Original Message-----
> > > From: Wayne Wengert [mailto:wayneDONTWANTSPAM@wengert.com]
> > > Posted At: Monday, January 24, 2005 5:25 AM
> > > Posted To: microsoft.public.dotnet.xml
> > > Conversation: Deserializing an array
> > > Subject: Deserializing an array
> > >
> > > Using VB.NET I want to read in an XML file that has an array of[/color]
> > objects[color=darkred]
> > > and
> > > then step through the resulting array in code. I build a class to[/color]
> > define[color=darkred]
> > > the
> > > structure and I am running code to read in the data but I can't[/color][/color][/color]
figure[color=blue][color=green]
> > out[color=darkred]
> > > where the data is in the resulting array. Most of the relevant[/color][/color][/color]
code is[color=blue][color=green][color=darkred]
> > > below. When I run the code to desrialize I get no errors but if I[/color][/color][/color]
try[color=blue][color=green]
> > to[color=darkred]
> > > look at some of the data via the command window I get errors such[/color][/color][/color]
as[color=blue][color=green]
> > this:[color=darkred]
> > >
> > > ?judges2.Judges(0).JudgeFirstName
> > >
> > > Index '0' for dimension '0' is out of range.
> > >
> > >
> > >
> > > What am I missing here?
> > >
> > >
> > >
> > > Wayne
> > >
> > >
> > >
> > > ================= Execution Code =======================
> > >
> > > Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e[/color][/color][/color]
As[color=blue][color=green][color=darkred]
> > > System.EventArgs) Handles btnImport.Click
> > >
> > > ReadJudgesTable("c:\2005 WGI\WGI Tabulation Program\Data
> > > Files\data\JudgesTable.xml")
> > >
> > > End Sub
> > >
> > > Protected Sub ReadJudgesTable(ByVal filename As String)
> > >
> > > Dim ser As New XmlSerializer(GetType(ArrayOfJudgeTableEntity))
> > >
> > > ' Read In the Judges table
> > >
> > > Dim fs2 As New FileStream(filename, FileMode.Open)
> > >
> > > ' Deserialize into another instance of ArrayOfJudgeTableEntity
> > >
> > > Dim judges2 As ArrayOfJudgeTableEntity =[/color][/color][/color]
CType(ser.Deserialize(fs2),[color=blue][color=green][color=darkred]
> > > ArrayOfJudgeTableEntity)
> > >
> > > fs2.Close()
> > >
> > > MsgBox("JudgesTable has been deserialized - I hope",
> > > MsgBoxStyle.Exclamation, "Got Judges")
> > >
> > > End Sub
> > >
> > > ================================================== ==
> > >
> > > ================== Class Definition ==================
> > >
> > > Imports System.Xml
> > >
> > > Imports System.Xml.Serialization
> > >
> > > Imports System.Collections
> > >
> > > Public Class ArrayOfJudgeTableEntity
> > >
> > > <XmlArray("JudgeTableEntity"), XmlArrayItem("Judge",[/color]
> > IsNullable:=True)> _[color=darkred]
> > >
> > > Public Judges() As Judge
> > >
> > >
> > > Public Sub New()
> > >
> > > End Sub 'New
> > >
> > > 'Public Sub New(ByVal id As String, ByVal fn As String, ByVal ln[/color][/color][/color]
As[color=blue][color=green][color=darkred]
> > > String,
> > > ByVal type As String)
> > >
> > > ' JudgeID = id
> > >
> > > ' JudgeFirstName = fn
> > >
> > > ' JudgeFirstName = ln
> > >
> > > ' JudgeType = type
> > >
> > > 'End Sub 'New
> > >
> > > End Class 'ArrayOfJudgeTableEntity
> > >
> > > Public Class Judge
> > >
> > > Public JudgeID As String
> > >
> > > Public JudgeFirstName As String
> > >
> > > Public JudgeLastName As String
> > >
> > > Public JudgeType As String
> > >
> > > Public Sub New()
> > >
> > > End Sub 'New
> > >
> > > Public Sub New(ByVal id As String, ByVal fn As String, ByVal ln As[/color]
> > String,[color=darkred]
> > > ByVal type As String)
> > >
> > > JudgeID = id
> > >
> > > JudgeType = type
> > >
> > > JudgeFirstName = fn
> > >
> > > JudgeLastName = ln
> > >
> > > End Sub 'New
> > >
> > > End Class 'Judge
> > >
> > > ====================================
> > >
> > >
> > >
> > > =========== Sample XML Data ================
> > >
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <ArrayOfJudgeTableEntity[/color][/color][/color]
xmlns:xsd="http://www.w3.org/2001/XMLSchema"[color=blue][color=green][color=darkred]
> > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> > > <JudgeTableEntity>
> > > <JudgeId>63371991-cdf9-4cc5-99c1-a42c599498f8</JudgeId>
> > > <JudgeFirstName>Kristen</JudgeFirstName>
> > > <JudgeLastName>O'Melia</JudgeLastName>
> > > <JudgeType>Equipment</JudgeType>
> > > </JudgeTableEntity>
> > > <JudgeTableEntity>
> > > <JudgeId>ce2c0c6e-4094-43da-9d8c-9726d81b017e</JudgeId>
> > > <JudgeFirstName>Smith</JudgeFirstName>
> > > <JudgeLastName>Dan</JudgeLastName>
> > > <JudgeType>Movement</JudgeType>
> > > </JudgeTableEntity>
> > > <JudgeTableEntity>
> > > <JudgeId>efe977f6-04ec-4a65-ae46-34b0f75de87f</JudgeId>
> > > <JudgeFirstName>Kathy</JudgeFirstName>
> > > <JudgeLastName>Whitcomb</JudgeLastName>
> > > <JudgeType>Ensemble Color Guard</JudgeType>
> > > </JudgeTableEntity>
> > > <JudgeTableEntity>
> > > <JudgeId>99d92f77-39e1-46b8-b9e2-446b8cea1b0c</JudgeId>
> > > <JudgeFirstName>Shirlee</JudgeFirstName>
> > > <JudgeLastName>Whitcomb</JudgeLastName>
> > > <JudgeType>General Effect Color Guard</JudgeType>
> > > </JudgeTableEntity>
> > > <JudgeTableEntity>
> > > <JudgeId>f7ae92ef-9bb2-48fe-bbe8-3c566b924d0f</JudgeId>
> > > <JudgeFirstName>George</JudgeFirstName>
> > > <JudgeLastName>Oliviero</JudgeLastName>
> > > <JudgeType>General Effect Color Guard</JudgeType>
> > > </JudgeTableEntity>
> > > <JudgeTableEntity>
> > > <JudgeId>5e1cad18-4ef9-4625-99c2-ee12c2b05cda</JudgeId>
> > > <JudgeFirstName>Lee</JudgeFirstName>
> > > <JudgeLastName>Carpenter</JudgeLastName>
> > > <JudgeType>Penalty</JudgeType>
> > > </JudgeTableEntity>
> > > </ArrayOfJudgeTableEntity>
> > >
> > > ==========================================[/color]
> >
> >[/color][/color]


Wayne Wengert
Guest
 
Posts: n/a
#5: Nov 12 '05

re: Deserializing an array


Christoph;

Thanks for that link - looks like a lot of good resources

As for my project, I found that my approach was giving an extra layer of
arrays - I am trying to work that out now. May be back for more help.

Wayne

"Christoph Schittko [MVP]" <INVALIDEMAIL@austin.rr.com> wrote in message
news:uFo4lGBBFHA.608@TK2MSFTNGP15.phx.gbl...[color=blue]
>
> I'm sorry, I didn't scroll down far enough last night to find the XML
> AND I didn't paste the link ... bad christoph
>
> The link I meant to include was:
>
> http://www.topxml.com/xmlserializer/...on_classes.asp.
>
> Looking at your classes though, this class definition would match
>
> <XmlArray("JudgeTableEntity"), XmlArrayItem("Judge", IsNullable:=True)>
> _
>
> Public Judges() As Judge
>
>
> This XML:
>
> <JudgeTableEntity>
> <Judge>
> ...
> </Judge>
> <Judge>
> ...
> </Judge>
> </JudgeTableEntity>
>
> Because you declare the class to map to XML with an enclosing XmlArray
> item <JudgeTableEntity> for array item elements <Judge>.
>
> In the example XML you posted though, there is no enclosing element
> around the array items. Instead, the array items are JudgeTableEntity
> elements.
>
> Change the class definition to:
>
> <XmlElement("JudgeTableEntity", IsNullable:=True)> _
> Public Judges() As Judge
>
> And you should be good to go.
>
> HTH,
> Christoph Schittko
> MVP XML
> http://weblogs.asp.net/cschittko
>
>[color=green]
> > -----Original Message-----
> > From: Wayne Wengert [mailto:wayneDONTWANTSPAM@wengert.com]
> > Posted At: Wednesday, January 26, 2005 3:28 PM
> > Posted To: microsoft.public.dotnet.xml
> > Conversation: Deserializing an array
> > Subject: Re: Deserializing an array
> >
> > Christoph;
> >
> > The code and XML was included in the post. I went to your web site but[/color]
> did[color=green]
> > not find the tutorial you mentioned. Exactly where is it?
> >
> > Wayne
> >
> > "Christoph Schittko [MVP]" <INVALIDEMAIL@austin.rr.com> wrote in[/color]
> message[color=green]
> > news:eiZk9c1AFHA.3376@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > >
> > > Wayne,
> > >
> > > It's hard to tell what's going on without seeing code and/or XML. I[/color][/color]
> have[color=green][color=darkred]
> > > a tutorial on serializing and deserializing arrays at [0]. Take a[/color][/color]
> look[color=green][color=darkred]
> > > and feel free to post back if you have additional questions.
> > >
> > > HTH,
> > > Christoph Schittko
> > > MVP XML
> > > http://weblogs.asp.net/cschittko
> > >
> > > > -----Original Message-----
> > > > From: Wayne Wengert [mailto:wayneDONTWANTSPAM@wengert.com]
> > > > Posted At: Monday, January 24, 2005 5:25 AM
> > > > Posted To: microsoft.public.dotnet.xml
> > > > Conversation: Deserializing an array
> > > > Subject: Deserializing an array
> > > >
> > > > Using VB.NET I want to read in an XML file that has an array of
> > > objects
> > > > and
> > > > then step through the resulting array in code. I build a class to
> > > define
> > > > the
> > > > structure and I am running code to read in the data but I can't[/color][/color]
> figure[color=green][color=darkred]
> > > out
> > > > where the data is in the resulting array. Most of the relevant[/color][/color]
> code is[color=green][color=darkred]
> > > > below. When I run the code to desrialize I get no errors but if I[/color][/color]
> try[color=green][color=darkred]
> > > to
> > > > look at some of the data via the command window I get errors such[/color][/color]
> as[color=green][color=darkred]
> > > this:
> > > >
> > > > ?judges2.Judges(0).JudgeFirstName
> > > >
> > > > Index '0' for dimension '0' is out of range.
> > > >
> > > >
> > > >
> > > > What am I missing here?
> > > >
> > > >
> > > >
> > > > Wayne
> > > >
> > > >
> > > >
> > > > ================= Execution Code =======================
> > > >
> > > > Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e[/color][/color]
> As[color=green][color=darkred]
> > > > System.EventArgs) Handles btnImport.Click
> > > >
> > > > ReadJudgesTable("c:\2005 WGI\WGI Tabulation Program\Data
> > > > Files\data\JudgesTable.xml")
> > > >
> > > > End Sub
> > > >
> > > > Protected Sub ReadJudgesTable(ByVal filename As String)
> > > >
> > > > Dim ser As New XmlSerializer(GetType(ArrayOfJudgeTableEntity))
> > > >
> > > > ' Read In the Judges table
> > > >
> > > > Dim fs2 As New FileStream(filename, FileMode.Open)
> > > >
> > > > ' Deserialize into another instance of ArrayOfJudgeTableEntity
> > > >
> > > > Dim judges2 As ArrayOfJudgeTableEntity =[/color][/color]
> CType(ser.Deserialize(fs2),[color=green][color=darkred]
> > > > ArrayOfJudgeTableEntity)
> > > >
> > > > fs2.Close()
> > > >
> > > > MsgBox("JudgesTable has been deserialized - I hope",
> > > > MsgBoxStyle.Exclamation, "Got Judges")
> > > >
> > > > End Sub
> > > >
> > > > ================================================== ==
> > > >
> > > > ================== Class Definition ==================
> > > >
> > > > Imports System.Xml
> > > >
> > > > Imports System.Xml.Serialization
> > > >
> > > > Imports System.Collections
> > > >
> > > > Public Class ArrayOfJudgeTableEntity
> > > >
> > > > <XmlArray("JudgeTableEntity"), XmlArrayItem("Judge",
> > > IsNullable:=True)> _
> > > >
> > > > Public Judges() As Judge
> > > >
> > > >
> > > > Public Sub New()
> > > >
> > > > End Sub 'New
> > > >
> > > > 'Public Sub New(ByVal id As String, ByVal fn As String, ByVal ln[/color][/color]
> As[color=green][color=darkred]
> > > > String,
> > > > ByVal type As String)
> > > >
> > > > ' JudgeID = id
> > > >
> > > > ' JudgeFirstName = fn
> > > >
> > > > ' JudgeFirstName = ln
> > > >
> > > > ' JudgeType = type
> > > >
> > > > 'End Sub 'New
> > > >
> > > > End Class 'ArrayOfJudgeTableEntity
> > > >
> > > > Public Class Judge
> > > >
> > > > Public JudgeID As String
> > > >
> > > > Public JudgeFirstName As String
> > > >
> > > > Public JudgeLastName As String
> > > >
> > > > Public JudgeType As String
> > > >
> > > > Public Sub New()
> > > >
> > > > End Sub 'New
> > > >
> > > > Public Sub New(ByVal id As String, ByVal fn As String, ByVal ln As
> > > String,
> > > > ByVal type As String)
> > > >
> > > > JudgeID = id
> > > >
> > > > JudgeType = type
> > > >
> > > > JudgeFirstName = fn
> > > >
> > > > JudgeLastName = ln
> > > >
> > > > End Sub 'New
> > > >
> > > > End Class 'Judge
> > > >
> > > > ====================================
> > > >
> > > >
> > > >
> > > > =========== Sample XML Data ================
> > > >
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <ArrayOfJudgeTableEntity[/color][/color]
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"[color=green][color=darkred]
> > > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> > > > <JudgeTableEntity>
> > > > <JudgeId>63371991-cdf9-4cc5-99c1-a42c599498f8</JudgeId>
> > > > <JudgeFirstName>Kristen</JudgeFirstName>
> > > > <JudgeLastName>O'Melia</JudgeLastName>
> > > > <JudgeType>Equipment</JudgeType>
> > > > </JudgeTableEntity>
> > > > <JudgeTableEntity>
> > > > <JudgeId>ce2c0c6e-4094-43da-9d8c-9726d81b017e</JudgeId>
> > > > <JudgeFirstName>Smith</JudgeFirstName>
> > > > <JudgeLastName>Dan</JudgeLastName>
> > > > <JudgeType>Movement</JudgeType>
> > > > </JudgeTableEntity>
> > > > <JudgeTableEntity>
> > > > <JudgeId>efe977f6-04ec-4a65-ae46-34b0f75de87f</JudgeId>
> > > > <JudgeFirstName>Kathy</JudgeFirstName>
> > > > <JudgeLastName>Whitcomb</JudgeLastName>
> > > > <JudgeType>Ensemble Color Guard</JudgeType>
> > > > </JudgeTableEntity>
> > > > <JudgeTableEntity>
> > > > <JudgeId>99d92f77-39e1-46b8-b9e2-446b8cea1b0c</JudgeId>
> > > > <JudgeFirstName>Shirlee</JudgeFirstName>
> > > > <JudgeLastName>Whitcomb</JudgeLastName>
> > > > <JudgeType>General Effect Color Guard</JudgeType>
> > > > </JudgeTableEntity>
> > > > <JudgeTableEntity>
> > > > <JudgeId>f7ae92ef-9bb2-48fe-bbe8-3c566b924d0f</JudgeId>
> > > > <JudgeFirstName>George</JudgeFirstName>
> > > > <JudgeLastName>Oliviero</JudgeLastName>
> > > > <JudgeType>General Effect Color Guard</JudgeType>
> > > > </JudgeTableEntity>
> > > > <JudgeTableEntity>
> > > > <JudgeId>5e1cad18-4ef9-4625-99c2-ee12c2b05cda</JudgeId>
> > > > <JudgeFirstName>Lee</JudgeFirstName>
> > > > <JudgeLastName>Carpenter</JudgeLastName>
> > > > <JudgeType>Penalty</JudgeType>
> > > > </JudgeTableEntity>
> > > > </ArrayOfJudgeTableEntity>
> > > >
> > > > ==========================================
> > >
> > >[/color][/color]
>
>[/color]


Closed Thread