473,386 Members | 1,997 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.

Serialization Problems

Hi guys,

I'm having trouble with serialization especially of array elements!

What I have is an array of clsUsers which have various properties as
shown in the code below

The XML I want to achieve is shown at the top and underneath that is
the xml i have achieved.... any help you can provide would be most
helpful!

Dave.

Code to Follow:
----------------------------------------------------------------
'''------Need to Achieve-------
'''<user_profiles>
''' <user>
''' <uid val="1" />
''' <username val="Dave" />
''' <password val="test" />
''' <level val="1" />
''' </user>
''' <user>
''' .
''' .
''' </user>
''' etc.
'''</user_profiles>

'''---------Actually Achieve--------
'''<ArrayOfClsUser>
''' <clsUser>
''' <username>1</username>
''' <uid>1</uid>
''' <password>1</password>
''' <level>OPERATOR</level>
''' </clsUser>
''' <clsUser>
''' <username>2</username>
''' <uid>2</uid>
''' <password>2</password>
''' <level>OPERATOR</level>
''' </clsUser>
''' etc.
'''</ArrayOfClsUser>

Imports System.Xml
Imports System.Xml.Serialization
'<XmlRoot(ElementName:="user_profiles", DataType:="anyURI",
IsNullable:=False, Namespace:="")> _
Public Class clsUserTable
<XmlElement(ElementName:="user_profiles")> _
Public allUsers As clsUser()

Private serializer As XmlSerializer
Private Sub SerializeUsers()
serializer = New XmlSerializer(allUsers.GetType())

Dim ns As New XmlSerializerNamespaces
ns.Add("", "")
Dim sb As New System.Text.StringBuilder
Dim tr As New XmlTextWriterFormattedNoDeclaration(New
IO.StringWriter(sb))
serializer.Serialize(tr, allUsers, ns)
Console.WriteLine(sb.ToString())
End Sub

Private Sub DeserializeUsers()
serializer = New XmlSerializer(Me.GetType())
Dim o As Object = serializer.Deserialize(New
IO.FileStream(Application.StartupPath & "\XMLData\xmlUsers.xml",
IO.FileMode.Open))
Dim t As clsUserTable = CType(o, clsUserTable)
allUsers = t.allUsers
End Sub

Private Class XmlTextWriterFormattedNoDeclaration
Inherits System.Xml.XmlTextWriter
Public Sub New(ByVal w As System.IO.TextWriter)
MyBase.New(w)
Formatting = System.Xml.Formatting.Indented
End Sub

Public Overloads Overrides Sub WriteStartDocument()

End Sub
End Class
End Class

'<XmlRoot(ElementName:="user")> _
Public Class clsUser
<XmlElement(ElementName:="username")> _
Public _username As String
<XmlElement(ElementName:="uid")> _
Public _UserIndex As Integer
<XmlElement(ElementName:="password")> _
Public _password As String
<XmlIgnore()> _
Public _Status As enumStatusLevel
<XmlElement(ElementName:="level")> _
Public _Oplevel As enumOperatorLevel

<XmlIgnore()> _
Public Property UserName() As String
Get
Return _username
End Get
Set(ByVal Value As String)
_username = Value
End Set
End Property

<XmlIgnore()> _
Public Property UserIndex() As Integer
Get
Return _UserIndex
End Get
Set(ByVal Value As Integer)
_UserIndex = Value
End Set
End Property

<XmlIgnore()> _
Public Property Password() As String
Get
Return _password
End Get
Set(ByVal Value As String)
_password = Value
End Set
End Property

<XmlIgnore()> _
Public Property OpLevel() As enumOperatorLevel
Get
Return _Oplevel
End Get
Set(ByVal Value As enumOperatorLevel)
_Oplevel = Value
End Set
End Property

<XmlIgnore()> _
Public Property Status() As enumStatusLevel
Get
Return _Status
End Get
Set(ByVal Value As enumStatusLevel)
_Status = Value
End Set
End Property

Public Overrides Function ToString() As String
Return UserName
End Function

Public Enum enumOperatorLevel
SUPERVISOR = 1
OPERATOR = 0
End Enum

Public Enum enumStatusLevel
ACTIVE = 0
INACTIVE = 1
End Enum
End Class

Nov 17 '05 #1
0 1014

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

Similar topics

2
by: Ante Sabo | last post by:
Hello, It seems to me to be in some kinda trouble. I wanted to implement communication between Java applet and Server through sockets and Serialization. So, I serialize Object, send it to server...
3
by: AA | last post by:
Hello I am having problems with a very simple serialization :( I download the schema http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0 and execute the xsd.exe for...
0
by: HakonB | last post by:
Hi all I get an exception when trying to deserialize a simple configuration file using XML Serialization. The very long stacktrace can be seen at the bottom of this message. I've see other...
2
by: Dominic | last post by:
Hi everybody, I'm planning to use serialization to persist an object (and possibly its child objects) in my application. However, I'm concerned about the backward compatibility issue. I'm...
4
by: Brian Keating | last post by:
wonder if anyone can help me here, i've a framework 1.1 dataset which i serialize in framework 1.1 and deserialize in framework 2.0. This is fine, problem is that i want to modify some of the...
0
by: Goethals Frederik | last post by:
Hi, I have some questions that are a little difficult to explain, so I give it a try... I have an application (aSP.NET with VB.NET codebehind) and I would like to store my data on disk...
3
by: Paulo Morgado [MVP] | last post by:
Hi all ..NET Framework 1.1 I have created several types that are serailized to XML as strings. Someting like this: public struct MyInt32 : IXmlSerializable { int value;
5
by: Harold Howe | last post by:
I am having a problem deserializing objects from a library when the following conditions exist: 1- The library is strongly named 2- The serialized file was created with version 1.0 of the...
5
by: RobinS | last post by:
I want to serialize a class that I am using to retain some information the user types into a screen. I have 3 questions. 1) I serialized it as XML to start with. This works, but how do I...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.