473,765 Members | 1,964 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 1484
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
2706
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
3774
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
4652
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
7084
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
9568
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
9399
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
10161
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
9955
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
6649
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
5275
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...
1
3924
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
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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.