473,799 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_profil es>
''' <user>
''' <uid val="1" />
''' <username val="Dave" />
''' <password val="test" />
''' <level val="1" />
''' </user>
''' <user>
''' .
''' .
''' </user>
''' etc.
'''</user_profiles>

'''---------Actually Achieve--------
'''<ArrayOfClsU ser>
''' <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.Seri alization
'<XmlRoot(Eleme ntName:="user_p rofiles", DataType:="anyU RI",
IsNullable:=Fal se, Namespace:="")> _
Public Class clsUserTable
<XmlElement(Ele mentName:="user _profiles")> _
Public allUsers As clsUser()

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

Dim ns As New XmlSerializerNa mespaces
ns.Add("", "")
Dim sb As New System.Text.Str ingBuilder
Dim tr As New XmlTextWriterFo rmattedNoDeclar ation(New
IO.StringWriter (sb))
serializer.Seri alize(tr, allUsers, ns)
Console.WriteLi ne(sb.ToString( ))
End Sub

Private Sub DeserializeUser s()
serializer = New XmlSerializer(M e.GetType())
Dim o As Object = serializer.Dese rialize(New
IO.FileStream(A pplication.Star tupPath & "\XMLData\xmlUs ers.xml",
IO.FileMode.Ope n))
Dim t As clsUserTable = CType(o, clsUserTable)
allUsers = t.allUsers
End Sub

Private Class XmlTextWriterFo rmattedNoDeclar ation
Inherits System.Xml.XmlT extWriter
Public Sub New(ByVal w As System.IO.TextW riter)
MyBase.New(w)
Formatting = System.Xml.Form atting.Indented
End Sub

Public Overloads Overrides Sub WriteStartDocum ent()

End Sub
End Class
End Class

'<XmlRoot(Eleme ntName:="user") > _
Public Class clsUser
<XmlElement(Ele mentName:="user name")> _
Public _username As String
<XmlElement(Ele mentName:="uid" )> _
Public _UserIndex As Integer
<XmlElement(Ele mentName:="pass word")> _
Public _password As String
<XmlIgnore()> _
Public _Status As enumStatusLevel
<XmlElement(Ele mentName:="leve l")> _
Public _Oplevel As enumOperatorLev el

<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 enumOperatorLev el
Get
Return _Oplevel
End Get
Set(ByVal Value As enumOperatorLev el)
_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 enumOperatorLev el
SUPERVISOR = 1
OPERATOR = 0
End Enum

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

Nov 17 '05 #1
0 1040

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

Similar topics

2
3006
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 which deserialize it with no problems. In other direction problems came out since Object serialized under Java 1.4.1 seems to be not deserializable under Java 1.1.4. (MS VM). If applet si run under J2, there are no problems, but I cannot push...
3
4857
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 create the classes. I load the file created in my project but when I try to serialize...
0
1621
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 messages related a similar error but none of the solutions suggested are valid in case :/ I have tracked the problem down to the compilation of the temporary DLL that handles the actual serialization. The following commandline (that is one single...
2
6215
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 evaluating if we can easily resolve this issue. For example, I have a class MyClass consisting of 100 fields.
4
7490
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 records in framework 2.0 and serialize the data so framework 1.1 can deserialize it and do what it required. Is this possible?
0
1253
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 because the users could continue later on there project with the same data already filled in. So I would use the soap-serialization to store the info (the nested objects, collections, ...). I think this process will work very well, also the
3
15108
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
6030
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 assembly 3- I am trying to deserialize from an EXE that references version 2.0 of the assembly 4- Both version 1.0 and 2.0 of the assembly reside in the GAC (no policy redirects exist).
5
4327
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 serialize the strings so that they are not messed up if they have XML in them, or control characters? Is there a way to do that in XML, or do I have to use BinaryFormatters? 2) So I tried using a binary formatter, and it won't serialize/deserialize...
1
11111
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
0
9538
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10247
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10023
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9067
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6803
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4135
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
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.