473,796 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Suppressing Collection node in XmlSerializatio n

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 1404
Found it, you just omit the XmlArray attribute i.e.

/// <summary>

/// Property Resources (EntityCollecti on)

/// </summary>

[XmlArrayItem("R esource", typeof(Entity))]

public EntityCollectio n Resources

{

get { return resources; }

set { resources = value; }

}
"Paul Hatcher" <ph******@nospa m.cix.co.uk> wrote in message
news:eI******** ******@TK2MSFTN GP12.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("MyXml CollectionName" )]

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

[XmlArrayItem("P erson"), typeof(Resource )]
[XmlArrayItem("M anager"), 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("Per son"), 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******@nospa m.cix.co.uk> wrote in message
news:e8******** ******@TK2MSFTN GP10.phx.gbl...
Found it, you just omit the XmlArray attribute i.e.

/// <summary>

/// Property Resources (EntityCollecti on)

/// </summary>

[XmlArrayItem("R esource", typeof(Entity))]

public EntityCollectio n Resources

{

get { return resources; }

set { resources = value; }

}
"Paul Hatcher" <ph******@nospa m.cix.co.uk> wrote in message
news:eI******** ******@TK2MSFTN GP12.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
3504
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 parameter where that parameter is of a type in the System.Data namespace // (or a class derived from something in the System.Data namespace). // Is there any way to prevent this from blowing up? using System;
5
2735
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 the appointment collection to populate the calendar control. The performance getting the XML data is fine, but loading the data into the collection is slow. My question/problem is should I be using the collection, a dataset, or something else to...
1
1652
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> <PRODUCT-DATE>01/01/2004</PRODUCT-DATE>
0
2146
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 a ArrayList and then retreive them: // Generate the arraylist with the modules that are checked foreach(TreeNode node in trv_Directories.Nodes)
6
1521
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 ids. I have built a collection of the right number of ids. I am using the following code to recursively go through the tree (some code left out). Pos is the position in the collection of ids - I need to select the correct ids (need to use previous...
2
1093
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
2141
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 and properties via XMLatrributes with a prefix of "THE_.."....except for the name of the child objects. This should say THE_NEW_Child but instead still persist in saying "NewChild" (Child properties are as planned) What's the solution?
4
1460
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 exposing, let's say, one property: name Public Class Event <XmlAttribute("name")_
2
1139
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; } public string SomeStringValue { get; set; } // etc... (2 more int and 7 more string properties, that's all.) }
0
9528
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
10455
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10173
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10006
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
9052
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...
1
7547
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2925
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.