473,473 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XmlArrayItem not allowed on Root Elements

I'm trying to serialize a collection, which is the root element,
however the items in the collection contain derived classes, and thus
give an error without XmlArrayItem attributes. However I can't add
these to the field I'm copying from as its the root element, and so
they appear to get ignored. Now the obvious answer is to put them in a
wrapper and serialize the wrapper, which is okay, but I was wondering
why this restriction is in place is can you get around it?

Mar 20 '06 #1
2 1871
Any Use ??
************************************************** *********

<XmlRoot(ElementName:="WhatEverWontBeSeeingThis" )> _
Public Class root_team
Public _players() As Footballer
End Class

Public Class Footballer
Public nickname As String
Public team As String
End Class
---------------------------------------
Public Shared Sub Main()

Dim serializeAPP As XmlSerializer
Dim t As New root_team
Dim p1 As New Footballer
Dim p2 As New Footballer
Dim p3 As New Footballer
serializeAPP = New XmlSerializer(Type:=GetType(Footballer()),
root:=New XmlRootAttribute("FavPlayers"))

p1.nickname = "Gazza"
p1.team = "Newcastle"

p1.nickname = "Besty"
p1.team = "Manchester Utd"

p2.nickname = "Leeper"
p2.team = "Glentoran"

t._players = New Footballer(2) {p1, p2, p3}

serializeAPP.Serialize(Console.Out, t._players)
Console.Read()

End Sub

Mar 21 '06 #2
Any Use ??
************************************************** *********

<XmlRoot(ElementName:="WhatEverWontBeSeeingThis" )> _
Public Class root_team
Public players() As Footballer
End Class

Public Class Footballer
Public nickname As String
Public team As String
End Class

---------------------------------------
Public Shared Sub Main()

Dim xsr As XmlSerializer
Dim t As New root_team
Dim p1 As New Footballer
Dim p2 As New Footballer
Dim p3 As New Footballer

xsr = New
XmlSerializer(Type:=GetType(Footballer()),
root:=New XmlRootAttribute("FavPlayers"))

p1.nickname = "Gazza"
p1.team = "Newcastle"

p2.nickname = "Besty"
p2.team = "Manchester Utd"

p3.nickname = "Leeper"
p3.team = "Glentoran"

t.players = New Footballer(2) {p1, p2, p3}

xsr.Serialize(Console.Out, t._players)
Console.Read()

End Sub

Mar 21 '06 #3

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

Similar topics

3
by: Christian | last post by:
HI NG, AFAIK, a dtd names the root element, i.e. <!DOCTYPE test SYSTEM "SomeURL"> must be followed by the root element named "test". However, Xerces 2.4.0 does not complain, if SomeURL...
12
by: pillepop2003 | last post by:
Hey! Can anyone give me a hint, how this problem is best implemented: I have a table of users (see below), where every user has one "superior user" (= parent node), this should be a fully...
3
by: Sascha Kerschhofer | last post by:
If I define more than one element "globally" in an XML schema, is there any hint which one is the actual root element for any instance document? e.g. <xs:schema...
0
by: Chatterbox | last post by:
Hello all, The XML file generated by the attached code correctly generates the <Items xsi:nil="true"/> element when serializing, but when deserializing, the Items field becomes an zero-sized...
0
by: Trollpower | last post by:
Hello NG, ive got authentication mode Forms. To access the root directory the user needs to authenticate using the login form. Additionally ive got a subfolder where the user has to authenticate...
9
by: MR | last post by:
I get the following Exception "The data at the root level is invalid. Line 1, position 642" whenever I try to deserialize an incoming SOAP message. The incoming message is formed well and its...
16
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument...
4
by: Hone | last post by:
I'm trying to serialize/deserialize the XML for an RSS 1.0 Feed (i.e. RDF) and the root element, as required by the standard, looks like this: <rdf:RDF ...> </rdf:RDF> However, I've tried...
2
by: doozer1979 | last post by:
Hello, I'm having a bit of difficulty transforming xml elements into attributes. I want to loop through all of the <person> elements in the document and turn all of its child elements into...
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
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,...
0
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...
0
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...
0
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,...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.