473,785 Members | 2,789 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 1403
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
2734
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
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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
10336
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...
0
10155
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...
1
10095
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
9953
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
6741
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();...
1
4054
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
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.