473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XML array of arrays serialization in VB

I'm trying to write an object hierarchy that is serialized into/from
XML file of the following structure:
<?xml version='1.0'>
<Session>
<Level1 attr1="1">
<Level2 attr2="11">TEXT11</Level2>
<Level2 attr2="12">TEXT12</Level2>
.................................................. .
</Level1>
<Level1 attr2="2">
<Level2 attr2="21">TEXT21</Level2>
<Level2 attr2="22">TEXT22</Level2>
.................................................. .
</Level1>
.................................
</Session>

Basically , Session is an array of Level1-s, and and Level1 is an array
of Level2-s.

MSDN give the following example for 1-level of hierarchy after
exclusion of irrelevant to my question details):
Option Explicit
Option Strict
Imports System
Imports System.IO
Imports System.Xml.Serialization
Imports Microsoft.VisualBasic
Public Class Group
<XmlArrayItem(GetType(Employee))> _
Public Employees() As Employee
End Class

Public Class Employee
Public Name As String
End Class

Public Class Run
Public Shared Sub Main()
Dim test As New Run()
test.SerializeObject("TypeDoc.xml")
test.DeserializeObject("TypeDoc.xml")
End Sub

Public Sub SerializeObject(ByVal filename As String)
Dim s As New XmlSerializer(GetType(Group))
Dim writer As New StreamWriter(filename)
Dim group As New Group()
Dim emp1 As New Employee()
Dim emp2 As New Employee()
emp1.Name = "Seiko"
emp2.Name = "Martina"
Dim emps() As Employee = {emp1, emp2}
group.Employees = emps
s.Serialize(writer, group)
writer.Close()
End Sub

Public Sub DeserializeObject(ByVal filename As String)
Dim fs As New FileStream(filename, FileMode.Open)
Dim x As New XmlSerializer(GetType(Group))
Dim g As Group = CType(x.Deserialize(fs), Group)
Console.WriteLine("Members:")
Dim e As Employee
For Each e In g.Employees
Console.WriteLine(ControlChars.Tab & e.Name)
Next e
End Sub
End Class

However, when I include similar code inside Employee so it contains an
array of another class type XXXX, creating
XmlSerializer(GetType(Group)) throws System.InvalidOperationException
with additional information "There was an error reflecting type
'SerExample.Group'.".

Could anybody post an example of how to create a correct object
hierarchy? Thank you.

May 1 '06 #1
0 1469

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

Similar topics

3
by: Franz | last post by:
Let me describe the flow of my program first. 1. Deserialize data from xml file. 2. Addition of "PersonType" class to the AllPersonalData. 3. Serialize data back to the xml file. My question is...
0
by: Wayne Wengert | last post by:
I have a basic understanding of XML and I have a similar basic grasp of VB.NET for developing Windows applications. I am still struggling with the when/where/how in the proper use of OO classes and...
4
by: Wayne Wengert | last post by:
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...
3
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on...
5
by: cql60 | last post by:
Hi all Pro, I have the class call "Person", and I do declare two dimensional array type of string inside this class which will keep "First_Name" and "Last_Name" as the record. When I try to...
3
by: Fireangel | last post by:
I want to cast a class into a byte array. I've seen some examples of this floating around, but they all have simple data members. What happens if I cast something that has a ArrayList or an...
1
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
2
by: tiberiu.motoc | last post by:
Hi. I've asked this question on the MSDN forums, but I've had no replies. I'm really stuck, so I'm gonna try my luck here. I have a Java web service which contains a simple function; the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.