473,881 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serializing Array with array "name" in the XML

I need help serializing an array without including the array "name". I am
writing in C# and using the XmlSerializer to serial classes.

I am trying to serialize a class with an array in it like the one below.

public class myclass
{
public imagecontext;
public myimage[] images;
}

public myimage
{
public string name;
public string path;
}

It will serialize something like this...

<myclass>
<imagecontext>m y context</imagecontext>
<images>
<myimage>
<name>Image1</name>
<path>somepat h</path>
</myimage>
<myimage>
<name>Image2</name>
<path>otherpath </path>
</myimage>
</images>
</myclass>

What I would really like is to get the XmlSerializer to not serialize the
name of the array (i.e. <images>). I need for the images to be children of
the <MyClass>, not children of <Images>. I want it to serialize like
below...

<myclass>
<imagecontext>m y context</imagecontext>
<myimage>
<name>Image1</name>
<path>somepat h</path>
</myimage>
<myimage>
<name>Image2</name>
<path>otherpath </path>
</myimage>
</myclass>


Jan 24 '06 #1
2 1487
Doing something like

public class myclass
{
public imagecontext;
[XmlElement(Type =typeof(myimage ),ElementName=" myimage")]
public myimage[] images;
}

may do what you are looking for.

"Rick Francis" <ri*********@ad elphia.net> wrote in message
news:s5******** ************@ad elphia.com...
I need help serializing an array without including the array "name". I am
writing in C# and using the XmlSerializer to serial classes.

I am trying to serialize a class with an array in it like the one below.

public class myclass
{
public imagecontext;
public myimage[] images;
}

public myimage
{
public string name;
public string path;
}

It will serialize something like this...

<myclass>
<imagecontext>m y context</imagecontext>
<images>
<myimage>
<name>Image1</name>
<path>somepat h</path>
</myimage>
<myimage>
<name>Image2</name>
<path>otherpath </path>
</myimage>
</images>
</myclass>

What I would really like is to get the XmlSerializer to not serialize the
name of the array (i.e. <images>). I need for the images to be children
of the <MyClass>, not children of <Images>. I want it to serialize like
below...

<myclass>
<imagecontext>m y context</imagecontext>
<myimage>
<name>Image1</name>
<path>somepat h</path>
</myimage>
<myimage>
<name>Image2</name>
<path>otherpath </path>
</myimage>
</myclass>

Jan 25 '06 #2
Clive,
Thanks, it worked great.

Rick Francis

"Clive Dixon" <cl************ *******@digita. noluncheonmeat. com> wrote in
message news:%2******** *******@tk2msft ngp13.phx.gbl.. .
Doing something like

public class myclass
{
public imagecontext;
[XmlElement(Type =typeof(myimage ),ElementName=" myimage")]
public myimage[] images;
}

may do what you are looking for.

"Rick Francis" <ri*********@ad elphia.net> wrote in message
news:s5******** ************@ad elphia.com...
I need help serializing an array without including the array "name". I am
writing in C# and using the XmlSerializer to serial classes.

I am trying to serialize a class with an array in it like the one below.

public class myclass
{
public imagecontext;
public myimage[] images;
}

public myimage
{
public string name;
public string path;
}

It will serialize something like this...

<myclass>
<imagecontext>m y context</imagecontext>
<images>
<myimage>
<name>Image1</name>
<path>somepat h</path>
</myimage>
<myimage>
<name>Image2</name>
<path>otherpath </path>
</myimage>
</images>
</myclass>

What I would really like is to get the XmlSerializer to not serialize the
name of the array (i.e. <images>). I need for the images to be children
of the <MyClass>, not children of <Images>. I want it to serialize like
below...

<myclass>
<imagecontext>m y context</imagecontext>
<myimage>
<name>Image1</name>
<path>somepat h</path>
</myimage>
<myimage>
<name>Image2</name>
<path>otherpath </path>
</myimage>
</myclass>


Jan 25 '06 #3

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

Similar topics

3
2713
by: Pavils Jurjans | last post by:
Hello, I have bumped upon this problem: I do some client-side form processing with JavaScript, and for this I loop over all the forms in the document. In order to identify them, I read their "name" property (which sources from "name" HTML attribue). The problem is, that if the form contains form control named "name", it overwrites the form name property. In fact, I'm quite surprised that it's so easy to spoil any of the form object...
14
3783
by: spike | last post by:
Im trying to write a program that should read through a binary file searching for the character sequence "\name\" Then it should read the characters following the "\name\" sequence until a NULL character is encountered. But when my program runs it gets a SIGSEGV (Segmentation vioalation) signal. Whats wrong? And is there a better way than mine to solve this task (most likely)
4
4657
by: ajschuster | last post by:
I cannot get my Javascript to work in Firefox. I am just trying to access the .name property of a DIV tag but it keeps coming back as "undefined". The same code works in IE and it works in Safari.... and if I change it to .id instead of .name it can read that so why wouldn't it be able to read the .name? I need urgent help!! Here's my code....
1
7095
by: mark | last post by:
Forgive me if this seems like a stupid question but I need help... I'm trying to do a simple online form that emails me the results from a few fields. Here is the code: <form action="http://cm1web1/WebSurveyComponents/script/ processform.asp" method="post">
0
9776
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
11105
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
10724
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
7954
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
7113
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();...
0
5781
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5978
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4599
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
4198
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.