473,563 Members | 2,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 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).JudgeFirstN ame

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.EventArg s) Handles btnImport.Click

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

End Sub

Protected Sub ReadJudgesTable (ByVal filename As String)

Dim ser As New XmlSerializer(G etType(ArrayOfJ udgeTableEntity ))

' Read In the Judges table

Dim fs2 As New FileStream(file name, FileMode.Open)

' Deserialize into another instance of ArrayOfJudgeTab leEntity

Dim judges2 As ArrayOfJudgeTab leEntity = CType(ser.Deser ialize(fs2),
ArrayOfJudgeTab leEntity)

fs2.Close()

MsgBox("JudgesT able has been deserialized - I hope",
MsgBoxStyle.Exc lamation, "Got Judges")

End Sub

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

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

Imports System.Xml

Imports System.Xml.Seri alization

Imports System.Collecti ons

Public Class ArrayOfJudgeTab leEntity

<XmlArray("Judg eTableEntity"), XmlArrayItem("J udge", IsNullable:=Tru e)> _

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 'ArrayOfJudgeTa bleEntity

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"?>
<ArrayOfJudgeTa bleEntity xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<JudgeTableEnti ty>
<JudgeId>633719 91-cdf9-4cc5-99c1-a42c599498f8</JudgeId>
<JudgeFirstName >Kristen</JudgeFirstName>
<JudgeLastName> O'Melia</JudgeLastName>
<JudgeType>Equi pment</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>ce2c0c 6e-4094-43da-9d8c-9726d81b017e</JudgeId>
<JudgeFirstName >Smith</JudgeFirstName>
<JudgeLastName> Dan</JudgeLastName>
<JudgeType>Move ment</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>efe977 f6-04ec-4a65-ae46-34b0f75de87f</JudgeId>
<JudgeFirstName >Kathy</JudgeFirstName>
<JudgeLastName> Whitcomb</JudgeLastName>
<JudgeType>Ense mble Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>99d92f 77-39e1-46b8-b9e2-446b8cea1b0c</JudgeId>
<JudgeFirstName >Shirlee</JudgeFirstName>
<JudgeLastName> Whitcomb</JudgeLastName>
<JudgeType>Gene ral Effect Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>f7ae92 ef-9bb2-48fe-bbe8-3c566b924d0f</JudgeId>
<JudgeFirstName >George</JudgeFirstName>
<JudgeLastName> Oliviero</JudgeLastName>
<JudgeType>Gene ral Effect Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>5e1cad 18-4ef9-4625-99c2-ee12c2b05cda</JudgeId>
<JudgeFirstName >Lee</JudgeFirstName>
<JudgeLastName> Carpenter</JudgeLastName>
<JudgeType>Pena lty</JudgeType>
</JudgeTableEntit y>
</ArrayOfJudgeTab leEntity>

=============== =============== ============
Nov 12 '05 #1
4 7504

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
-----Original Message-----
From: Wayne Wengert [mailto:wa****** *********@wenge rt.com]
Posted At: Monday, January 24, 2005 5:25 AM
Posted To: microsoft.publi c.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 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).JudgeFirstN ame

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.EventArg s) Handles btnImport.Click

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

End Sub

Protected Sub ReadJudgesTable (ByVal filename As String)

Dim ser As New XmlSerializer(G etType(ArrayOfJ udgeTableEntity ))

' Read In the Judges table

Dim fs2 As New FileStream(file name, FileMode.Open)

' Deserialize into another instance of ArrayOfJudgeTab leEntity

Dim judges2 As ArrayOfJudgeTab leEntity = CType(ser.Deser ialize(fs2),
ArrayOfJudgeTab leEntity)

fs2.Close()

MsgBox("JudgesT able has been deserialized - I hope",
MsgBoxStyle.Exc lamation, "Got Judges")

End Sub

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

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

Imports System.Xml

Imports System.Xml.Seri alization

Imports System.Collecti ons

Public Class ArrayOfJudgeTab leEntity

<XmlArray("Judg eTableEntity"), XmlArrayItem("J udge", IsNullable:=Tru e)> _
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 'ArrayOfJudgeTa bleEntity

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"?>
<ArrayOfJudgeTa bleEntity xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<JudgeTableEnti ty>
<JudgeId>633719 91-cdf9-4cc5-99c1-a42c599498f8</JudgeId>
<JudgeFirstName >Kristen</JudgeFirstName>
<JudgeLastName> O'Melia</JudgeLastName>
<JudgeType>Equi pment</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>ce2c0c 6e-4094-43da-9d8c-9726d81b017e</JudgeId>
<JudgeFirstName >Smith</JudgeFirstName>
<JudgeLastName> Dan</JudgeLastName>
<JudgeType>Move ment</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>efe977 f6-04ec-4a65-ae46-34b0f75de87f</JudgeId>
<JudgeFirstName >Kathy</JudgeFirstName>
<JudgeLastName> Whitcomb</JudgeLastName>
<JudgeType>Ense mble Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>99d92f 77-39e1-46b8-b9e2-446b8cea1b0c</JudgeId>
<JudgeFirstName >Shirlee</JudgeFirstName>
<JudgeLastName> Whitcomb</JudgeLastName>
<JudgeType>Gene ral Effect Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>f7ae92 ef-9bb2-48fe-bbe8-3c566b924d0f</JudgeId>
<JudgeFirstName >George</JudgeFirstName>
<JudgeLastName> Oliviero</JudgeLastName>
<JudgeType>Gene ral Effect Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>5e1cad 18-4ef9-4625-99c2-ee12c2b05cda</JudgeId>
<JudgeFirstName >Lee</JudgeFirstName>
<JudgeLastName> Carpenter</JudgeLastName>
<JudgeType>Pena lty</JudgeType>
</JudgeTableEntit y>
</ArrayOfJudgeTab leEntity>

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

Nov 12 '05 #2
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]" <IN**********@a ustin.rr.com> wrote in message
news:ei******** ******@TK2MSFTN GP12.phx.gbl...

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
-----Original Message-----
From: Wayne Wengert [mailto:wa****** *********@wenge rt.com]
Posted At: Monday, January 24, 2005 5:25 AM
Posted To: microsoft.publi c.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 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).JudgeFirstN ame

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.EventArg s) Handles btnImport.Click

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

End Sub

Protected Sub ReadJudgesTable (ByVal filename As String)

Dim ser As New XmlSerializer(G etType(ArrayOfJ udgeTableEntity ))

' Read In the Judges table

Dim fs2 As New FileStream(file name, FileMode.Open)

' Deserialize into another instance of ArrayOfJudgeTab leEntity

Dim judges2 As ArrayOfJudgeTab leEntity = CType(ser.Deser ialize(fs2),
ArrayOfJudgeTab leEntity)

fs2.Close()

MsgBox("JudgesT able has been deserialized - I hope",
MsgBoxStyle.Exc lamation, "Got Judges")

End Sub

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

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

Imports System.Xml

Imports System.Xml.Seri alization

Imports System.Collecti ons

Public Class ArrayOfJudgeTab leEntity

<XmlArray("Judg eTableEntity"), XmlArrayItem("J udge",

IsNullable:=Tru e)> _

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 'ArrayOfJudgeTa bleEntity

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"?>
<ArrayOfJudgeTa bleEntity xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<JudgeTableEnti ty>
<JudgeId>633719 91-cdf9-4cc5-99c1-a42c599498f8</JudgeId>
<JudgeFirstName >Kristen</JudgeFirstName>
<JudgeLastName> O'Melia</JudgeLastName>
<JudgeType>Equi pment</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>ce2c0c 6e-4094-43da-9d8c-9726d81b017e</JudgeId>
<JudgeFirstName >Smith</JudgeFirstName>
<JudgeLastName> Dan</JudgeLastName>
<JudgeType>Move ment</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>efe977 f6-04ec-4a65-ae46-34b0f75de87f</JudgeId>
<JudgeFirstName >Kathy</JudgeFirstName>
<JudgeLastName> Whitcomb</JudgeLastName>
<JudgeType>Ense mble Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>99d92f 77-39e1-46b8-b9e2-446b8cea1b0c</JudgeId>
<JudgeFirstName >Shirlee</JudgeFirstName>
<JudgeLastName> Whitcomb</JudgeLastName>
<JudgeType>Gene ral Effect Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>f7ae92 ef-9bb2-48fe-bbe8-3c566b924d0f</JudgeId>
<JudgeFirstName >George</JudgeFirstName>
<JudgeLastName> Oliviero</JudgeLastName>
<JudgeType>Gene ral Effect Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>5e1cad 18-4ef9-4625-99c2-ee12c2b05cda</JudgeId>
<JudgeFirstName >Lee</JudgeFirstName>
<JudgeLastName> Carpenter</JudgeLastName>
<JudgeType>Pena lty</JudgeType>
</JudgeTableEntit y>
</ArrayOfJudgeTab leEntity>

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


Nov 12 '05 #3

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("Judg eTableEntity"), XmlArrayItem("J udge", IsNullable:=Tru e)>
_

Public Judges() As Judge
This XML:

<JudgeTableEnti ty>
<Judge>
....
</Judge>
<Judge>
....
</Judge>
</JudgeTableEntit y>

Because you declare the class to map to XML with an enclosing XmlArray
item <JudgeTableEnti ty> 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 JudgeTableEntit y
elements.

Change the class definition to:

<XmlElement("Ju dgeTableEntity" , IsNullable:=Tru e)> _
Public Judges() As Judge

And you should be good to go.

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

-----Original Message-----
From: Wayne Wengert [mailto:wa****** *********@wenge rt.com]
Posted At: Wednesday, January 26, 2005 3:28 PM
Posted To: microsoft.publi c.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 did not find the tutorial you mentioned. Exactly where is it?

Wayne

"Christoph Schittko [MVP]" <IN**********@a ustin.rr.com> wrote in message news:ei******** ******@TK2MSFTN GP12.phx.gbl...

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
-----Original Message-----
From: Wayne Wengert [mailto:wa****** *********@wenge rt.com]
Posted At: Monday, January 24, 2005 5:25 AM
Posted To: microsoft.publi c.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 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).JudgeFirstN ame

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.EventArg s) Handles btnImport.Click

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

End Sub

Protected Sub ReadJudgesTable (ByVal filename As String)

Dim ser As New XmlSerializer(G etType(ArrayOfJ udgeTableEntity ))

' Read In the Judges table

Dim fs2 As New FileStream(file name, FileMode.Open)

' Deserialize into another instance of ArrayOfJudgeTab leEntity

Dim judges2 As ArrayOfJudgeTab leEntity = CType(ser.Deser ialize(fs2), ArrayOfJudgeTab leEntity)

fs2.Close()

MsgBox("JudgesT able has been deserialized - I hope",
MsgBoxStyle.Exc lamation, "Got Judges")

End Sub

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

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

Imports System.Xml

Imports System.Xml.Seri alization

Imports System.Collecti ons

Public Class ArrayOfJudgeTab leEntity

<XmlArray("Judg eTableEntity"), XmlArrayItem("J udge",

IsNullable:=Tru e)> _

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 'ArrayOfJudgeTa bleEntity

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"?>
<ArrayOfJudgeTa bleEntity xmlns:xsd="http ://www.w3.org/2001/XMLSchema" xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<JudgeTableEnti ty>
<JudgeId>633719 91-cdf9-4cc5-99c1-a42c599498f8</JudgeId>
<JudgeFirstName >Kristen</JudgeFirstName>
<JudgeLastName> O'Melia</JudgeLastName>
<JudgeType>Equi pment</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>ce2c0c 6e-4094-43da-9d8c-9726d81b017e</JudgeId>
<JudgeFirstName >Smith</JudgeFirstName>
<JudgeLastName> Dan</JudgeLastName>
<JudgeType>Move ment</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>efe977 f6-04ec-4a65-ae46-34b0f75de87f</JudgeId>
<JudgeFirstName >Kathy</JudgeFirstName>
<JudgeLastName> Whitcomb</JudgeLastName>
<JudgeType>Ense mble Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>99d92f 77-39e1-46b8-b9e2-446b8cea1b0c</JudgeId>
<JudgeFirstName >Shirlee</JudgeFirstName>
<JudgeLastName> Whitcomb</JudgeLastName>
<JudgeType>Gene ral Effect Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>f7ae92 ef-9bb2-48fe-bbe8-3c566b924d0f</JudgeId>
<JudgeFirstName >George</JudgeFirstName>
<JudgeLastName> Oliviero</JudgeLastName>
<JudgeType>Gene ral Effect Color Guard</JudgeType>
</JudgeTableEntit y>
<JudgeTableEnti ty>
<JudgeId>5e1cad 18-4ef9-4625-99c2-ee12c2b05cda</JudgeId>
<JudgeFirstName >Lee</JudgeFirstName>
<JudgeLastName> Carpenter</JudgeLastName>
<JudgeType>Pena lty</JudgeType>
</JudgeTableEntit y>
</ArrayOfJudgeTab leEntity>

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


Nov 12 '05 #4
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]" <IN**********@a ustin.rr.com> wrote in message
news:uF******** *****@TK2MSFTNG P15.phx.gbl...

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("Judg eTableEntity"), XmlArrayItem("J udge", IsNullable:=Tru e)>
_

Public Judges() As Judge
This XML:

<JudgeTableEnti ty>
<Judge>
...
</Judge>
<Judge>
...
</Judge>
</JudgeTableEntit y>

Because you declare the class to map to XML with an enclosing XmlArray
item <JudgeTableEnti ty> 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 JudgeTableEntit y
elements.

Change the class definition to:

<XmlElement("Ju dgeTableEntity" , IsNullable:=Tru e)> _
Public Judges() As Judge

And you should be good to go.

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

-----Original Message-----
From: Wayne Wengert [mailto:wa****** *********@wenge rt.com]
Posted At: Wednesday, January 26, 2005 3:28 PM
Posted To: microsoft.publi c.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

did
not find the tutorial you mentioned. Exactly where is it?

Wayne

"Christoph Schittko [MVP]" <IN**********@a ustin.rr.com> wrote in

message
news:ei******** ******@TK2MSFTN GP12.phx.gbl...

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

> -----Original Message-----
> From: Wayne Wengert [mailto:wa****** *********@wenge rt.com]
> Posted At: Monday, January 24, 2005 5:25 AM
> Posted To: microsoft.publi c.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 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).JudgeFirstN ame
>
> 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.EventArg s) Handles btnImport.Click
>
> ReadJudgesTable ("c:\2005 WGI\WGI Tabulation Program\Data
> Files\data\Judg esTable.xml")
>
> End Sub
>
> Protected Sub ReadJudgesTable (ByVal filename As String)
>
> Dim ser As New XmlSerializer(G etType(ArrayOfJ udgeTableEntity ))
>
> ' Read In the Judges table
>
> Dim fs2 As New FileStream(file name, FileMode.Open)
>
> ' Deserialize into another instance of ArrayOfJudgeTab leEntity
>
> Dim judges2 As ArrayOfJudgeTab leEntity = CType(ser.Deser ialize(fs2), > ArrayOfJudgeTab leEntity)
>
> fs2.Close()
>
> MsgBox("JudgesT able has been deserialized - I hope",
> MsgBoxStyle.Exc lamation, "Got Judges")
>
> End Sub
>
> =============== =============== =============== =======
>
> =============== === Class Definition =============== ===
>
> Imports System.Xml
>
> Imports System.Xml.Seri alization
>
> Imports System.Collecti ons
>
> Public Class ArrayOfJudgeTab leEntity
>
> <XmlArray("Judg eTableEntity"), XmlArrayItem("J udge",
IsNullable:=Tru e)> _
>
> 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 'ArrayOfJudgeTa bleEntity
>
> 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"?>
> <ArrayOfJudgeTa bleEntity xmlns:xsd="http ://www.w3.org/2001/XMLSchema" > xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
> <JudgeTableEnti ty>
> <JudgeId>633719 91-cdf9-4cc5-99c1-a42c599498f8</JudgeId>
> <JudgeFirstName >Kristen</JudgeFirstName>
> <JudgeLastName> O'Melia</JudgeLastName>
> <JudgeType>Equi pment</JudgeType>
> </JudgeTableEntit y>
> <JudgeTableEnti ty>
> <JudgeId>ce2c0c 6e-4094-43da-9d8c-9726d81b017e</JudgeId>
> <JudgeFirstName >Smith</JudgeFirstName>
> <JudgeLastName> Dan</JudgeLastName>
> <JudgeType>Move ment</JudgeType>
> </JudgeTableEntit y>
> <JudgeTableEnti ty>
> <JudgeId>efe977 f6-04ec-4a65-ae46-34b0f75de87f</JudgeId>
> <JudgeFirstName >Kathy</JudgeFirstName>
> <JudgeLastName> Whitcomb</JudgeLastName>
> <JudgeType>Ense mble Color Guard</JudgeType>
> </JudgeTableEntit y>
> <JudgeTableEnti ty>
> <JudgeId>99d92f 77-39e1-46b8-b9e2-446b8cea1b0c</JudgeId>
> <JudgeFirstName >Shirlee</JudgeFirstName>
> <JudgeLastName> Whitcomb</JudgeLastName>
> <JudgeType>Gene ral Effect Color Guard</JudgeType>
> </JudgeTableEntit y>
> <JudgeTableEnti ty>
> <JudgeId>f7ae92 ef-9bb2-48fe-bbe8-3c566b924d0f</JudgeId>
> <JudgeFirstName >George</JudgeFirstName>
> <JudgeLastName> Oliviero</JudgeLastName>
> <JudgeType>Gene ral Effect Color Guard</JudgeType>
> </JudgeTableEntit y>
> <JudgeTableEnti ty>
> <JudgeId>5e1cad 18-4ef9-4625-99c2-ee12c2b05cda</JudgeId>
> <JudgeFirstName >Lee</JudgeFirstName>
> <JudgeLastName> Carpenter</JudgeLastName>
> <JudgeType>Pena lty</JudgeType>
> </JudgeTableEntit y>
> </ArrayOfJudgeTab leEntity>
>
> =============== =============== ============


Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2040
by: Justin Armstrong | last post by:
I'm having difficulties deserializing some objects. Consider the following example of what I'm trying to do: ---------------------------------------------------------- class Person { string name; } class Info {
5
4620
by: Artur Niesporek | last post by:
Hi guys, when receiving a soap response posted back from a server i get the following error when deserializing the soap message. The problem seems to be with the item-collection of the nightlyrate-Array. .] Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Re ad6_nightlyratearray()
0
1968
by: Casey | last post by:
So I'm using XmlSerializer to serialize out a wrapper object that contains an arbitrary number of other objects. The class definitions listed below are made to be very generic. Some of the objects contain other objects so when I declare my XmlSerializer I need to send along an array of types to be included in the serialization. That works...
2
3088
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string format. I can, of course, serialize a class to a file, either binary or XML, but this is not what I am looking for. Currently I am using ToString() or...
1
1312
by: Kevin R | last post by:
Hi All, I have a binary file, the first few k of which contains some information which I need to stick in to an array of types,let's call them Wongas. Each Wonga is made up of two ulongs and a 24 byte character array. I need to read in an array of Wongas from the binary file and I need to specify how many to read in, as the file is only...
2
7952
by: ce | last post by:
Being a newbie regarding serialization and memorystreams, I was trying to see if i could improve page performance (avoiding going to the db on a postback) by saving my serialized business object in viewstate and getting it back from the client on a postback. But the last line of the sample code below throws a "Stream was not readable" error...
1
4974
by: GAURAV KRISHNA | last post by:
I am able to deserialize an array using XMLSerializer but the size of an array is 0.The problem seems to be because of unqualified element name but I am not very sure. Here is what I did: I get the following xml from the server ===================================================
0
7786
by: Sivajee Akula | last post by:
Hello All, I am trying to consume a .NET Service from Adobe LiveCycle Workflow. The service deals with complex objects. I am getting the following exception at the time of invocation of the service, and due to which my workflow gets stalled. When I searched the net, I found many posts reporting this error, but none with a solution. There is...
2
1553
by: Chris | last post by:
I need to serialise a business object into a session as a string. The reason for this is that we have to run session state with classic ASP and the code we use in effect mean ASP.net sessions can only handle strings. My initial thought is to serialize the object into a string and put it into the session but I am having problem deserializing...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.