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

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>my context</imagecontext>
<images>
<myimage>
<name>Image1</name>
<path>somepath</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>my context</imagecontext>
<myimage>
<name>Image1</name>
<path>somepath</path>
</myimage>
<myimage>
<name>Image2</name>
<path>otherpath</path>
</myimage>
</myclass>


Jan 24 '06 #1
2 1454
Doing something like

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

may do what you are looking for.

"Rick Francis" <ri*********@adelphia.net> wrote in message
news:s5********************@adelphia.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>my context</imagecontext>
<images>
<myimage>
<name>Image1</name>
<path>somepath</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>my context</imagecontext>
<myimage>
<name>Image1</name>
<path>somepath</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***************@tk2msftngp13.phx.gbl...
Doing something like

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

may do what you are looking for.

"Rick Francis" <ri*********@adelphia.net> wrote in message
news:s5********************@adelphia.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>my context</imagecontext>
<images>
<myimage>
<name>Image1</name>
<path>somepath</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>my context</imagecontext>
<myimage>
<name>Image1</name>
<path>somepath</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
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...
14
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...
4
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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
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
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...

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.