TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
jamc
NA
4
0
help!! element name changes case during xml serialization
Jan 18 2009 1:38 PM
I'm building an app that requires xml serialization and I've encountered a problem where the xmlserializer is changing the case of the root node during serialization.
I've created the following two classes; one to represent the object I'm working with and another to act as a collection.
<XmlRoot(
"user"
)> _
Public Class
User
Private
propUserName
As String
<XmlAttribute(
"username"
)> _
Public Property
UserName()
As String
Get
Return
propUserName
End Get
Set
(
ByVal
value
As String
)
propUserName = value
End Set
End Property
End Class
and the second class to hold the user classes in a collection...
<XmlRoot(
"users"
)> _
Partial Public Class
UserCollection
Inherits
ArrayList
<XmlElement(
"user"
)> _
Default Public Shadows Property
Item(
ByVal
index
As Integer
)
As
User
Get
Return MyBase
.Item(index)
End Get
Set
(
ByVal
Item
As
User
)
MyBase
.Item(index) = Item
End Set
End Property
End Class
Serializing the user class on it's own produces an output I would expect;
<user username="value"/>
But serializing the user collection class produces a problem. For some reason the XmlSerializer converts the element names into pascal case (first letter is a capital) instead of camel case (i.e. myBase) - meaning that I get an output like this;
<users>
<
U
ser
username="value"/>
</users>
This causes a problem when I try to deserialize the xml string back into an object, as the XmlSerializer is expecting "user" not "User" (defined in both classes), and doesn't add the user class to the usercollection class like it should.
I've tried everything I can think of to get to the bottom of this one, but no luck. Can anyone throw some light on why this might be happening?
Reply
Answers (
2
)
Convert different formats of XML to custom format
hlep wiht login form/xml..