473,503 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlSerializer: ArrayList vs. anyType

1 New Member
I am trying to serialize a class derived from ArrayList called JobQueue that contains an array of objects of the class Job. Using XmlSerializer I can get this to serialize successfully, but I am unable to change the name of the Job element from "anyType" to "Job". It is somewhat of a nit but it does bother me that I'm not understanding the attributes well enough to make this simple change. I have tried numerous options and now I'm just frustrated. Could this have anything to do with my JobQueue class being static? Anyway, some code below.

// My JobQueue class:
[XmlRoot("JobQueue")]
[XmlInclude(typeof(Job))]
public class JobQueue : ArrayList
{
[XmlArray(ElementName = "Job")]
[XmlArrayItem(ElementName = "Job")]
public static JobQueue TheJobQueue;
...
// My Job class:
public class Job
{
// constructor
public Job()
{
fileList = new ArrayList();
timeStamp = DateTime.Now;
}
...
// with some attributes and a nested element
[XmlArray(ElementName="FileList")]
[XmlArrayItem(ElementName="File")]
public ArrayList fileList; // list of WAV files
[XmlAttributeAttribute("TimeStamp")]
public DateTime timeStamp; // timestamp job was submitted
...

And the output XML looks like this:
<?xml version="1.0" encoding="utf-8"?>
<JobQueue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<anyType xsi:type="Job" TimeStamp="2006-08-17T14:50:38.9425488-05:00">
<FileList>
<File xsi:type="xsd:string">C:\CD Data</File>
</FileList>
</anyType>
</JobQueue>

What I really want to see is more like:
<?xml version="1.0" encoding="utf-8"?>
<JobQueue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Job xsi:type="Job" TimeStamp="2006-08-17T14:50:38.9425488-05:00">
<FileList>
<File xsi:type="xsd:string">C:\CD Data</File>
</FileList>
</Job>
</JobQueue>

Thanks in advance for any assistance.
Jon
Aug 17 '06 #1
1 5169
Rodders
1 New Member
Try:
public class SomeClass
{
[XmlArray("JobQueue"), XmlArrayItem("Job", typeof(Job))]
ArrayList JobQueue = new ArrayList();
}

to get, for example:
<JobQueue>
<Job>Job 1</Job>
<Job>Job 2</Job>
</JobQueue>
Sep 20 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
12616
by: Christopher Pragash | last post by:
Hello all, I'm trying to persist an object of type Arraylist into XML using the following the XMLSerializer and it returns an "Unknown" Error. I'm able to serialize and deserialize the arraylist...
4
11348
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
2
942
by: magister | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different...
1
4603
by: Jamus Sprinson | last post by:
Before I continue, I'm going to begin by saying I'm not by any means an expert- I've been using .NET with C# for about 4 months now, and basically just learning by example and docs. A game...
0
1054
by: maersa | last post by:
Hi all, i'm serializing an arraylist like the following with an "Role" object as it's item. ----------------------------------------------------- ---- ArrayList ar = new ArrayList();...
2
10030
by: Steven | last post by:
Hello, In my asp.net application, I have the MainForm.aspx.cs (where all the functions are defined) and ClasssificationInfo.cs class. This is the Classification Info class -- using System;...
5
8007
by: Brad | last post by:
I would like to serialize an arraylist of objects to xml so I can store the xml in a database column. How would I code the serializing and deserializing? Below is a (overly) simple, incomplete...
3
2339
by: Michael Slattery | last post by:
Hello, I see quite a few questions, but no valid responses to the question... How do I store an ArrayList of items in a Properties file via the GUI? I am able to select the...
0
1409
by: Igor | last post by:
I have a web method that returns an ArrayList. Everything works fine except that I can't get rid of thos ArrayOfAnyType tags! I've tried using: public ArrayList Method(){...} but it...
0
7199
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
7274
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,...
0
7323
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...
1
6984
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
7453
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
5576
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,...
0
1507
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 ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
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...

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.