473,406 Members | 2,549 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,406 software developers and data experts.

Suppressing Collection node in XmlSerialization

Is it possible to serialize a collection so that the collection itself does
not appear e.g.

<Document>
<Resource>
<name>a</name>
</Resource>
</Document>

rather than

<Document>
<Resources>
<Resource>
<name>a</name>
</Resource>
</Resources>
</Document>

I know I can do it if I have an array of items, but I'd prefer a collection
if at all possible

TIA

Paul
Nov 12 '05 #1
2 1389
Found it, you just omit the XmlArray attribute i.e.

/// <summary>

/// Property Resources (EntityCollection)

/// </summary>

[XmlArrayItem("Resource", typeof(Entity))]

public EntityCollection Resources

{

get { return resources; }

set { resources = value; }

}
"Paul Hatcher" <ph******@nospam.cix.co.uk> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...
Is it possible to serialize a collection so that the collection itself
does not appear e.g.

<Document>
<Resource>
<name>a</name>
</Resource>
</Document>

rather than

<Document>
<Resources>
<Resource>
<name>a</name>
</Resource>
</Resources>
</Document>

I know I can do it if I have an array of items, but I'd prefer a
collection if at all possible

TIA

Paul

Nov 12 '05 #2
Sorry, got it slightly wrong, if you want a collection element and need to
name it differently use

[XmlArray("MyXmlCollectionName")]

Then, for the the items you can have multiple XmlArrayItem values e.g.

[XmlArrayItem("Person"), typeof(Resource)]
[XmlArrayItem("Manager"), typeof(Manager)]

Note that all of the items have to be derived from the base class that
collection managers

If you *don't* want the collection element, then use

[XmlElement("Person"), tyipeof(Person)]

I'm sure I've found this out before, but it's not that well documented on
MSDN.

Regards

Paul

"Paul Hatcher" <ph******@nospam.cix.co.uk> wrote in message
news:e8**************@TK2MSFTNGP10.phx.gbl...
Found it, you just omit the XmlArray attribute i.e.

/// <summary>

/// Property Resources (EntityCollection)

/// </summary>

[XmlArrayItem("Resource", typeof(Entity))]

public EntityCollection Resources

{

get { return resources; }

set { resources = value; }

}
"Paul Hatcher" <ph******@nospam.cix.co.uk> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...
Is it possible to serialize a collection so that the collection itself
does not appear e.g.

<Document>
<Resource>
<name>a</name>
</Resource>
</Document>

rather than

<Document>
<Resources>
<Resource>
<name>a</name>
</Resource>
</Resources>
</Document>

I know I can do it if I have an array of items, but I'd prefer a
collection if at all possible

TIA

Paul


Nov 12 '05 #3

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

Similar topics

3
by: Craig Schneider | last post by:
// Can anyone explain the bizarre XML Serialization behavior seen in the following code. // It seems that a collection can not be XML Serialized if it contains an Add() method // with a single...
5
by: Kurt Bauer | last post by:
I have an ASP group calendar application which pulls calendar data from Exchange via webdav into an XML string. I then loop the XML nodes to populate a collection of appointments. Finally I use...
1
by: chris yoker via DotNetMonster.com | last post by:
hiya, I add new nodes to an xmlDoc. I want to add "innerText" to every newly-created node. current XML file <code> <rows> <row> <PRODUCT-TYPE>bike</PRODUCT-TYPE>...
0
by: Ferrari.NET | last post by:
Hi all I have a treeview in a form that I need to store inside a nodes collection so I'll not loose the values when I change between screens. What I'm doing is store all the checked nodes into...
6
by: Jan Krouwer | last post by:
I have a treeview which is populated from a relational database. In order to copy part of the tree, I need to add to the database the relationship of the part of the tree to be copied but with new...
2
by: PH | last post by:
Hi guys; I got the following problem to solve, hope you can help me. I got a XML node in App.Conf; <CUSTOMERS> <CUSTOMER> <NAME =”Frank” />
1
by: DesperateDan | last post by:
I've got a parent object that is a collection and it in turn is hosting 2 child objects. My searlization has worked perfectly to plan in as much that I wanted to dictate the names of the objects...
4
by: xke | last post by:
Why the collection property is not included in the ouput serialization ? I have a custom generic collection (implements icollection): Events of objects: Event. Event is a simple class...
2
by: Jordan S. | last post by:
Using .NET 3.5... I have the following class: class NodeDescriptor { // Properties only in this class public int NodeID { get; private set; } public int ParentNodeID { get; private set; }...
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
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?
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.