473,654 Members | 3,251 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("JobQue ue")]
[XmlInclude(type of(Job))]
public class JobQueue : ArrayList
{
[XmlArray(Elemen tName = "Job")]
[XmlArrayItem(El ementName = "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(Elemen tName="FileList ")]
[XmlArrayItem(El ementName="File ")]
public ArrayList fileList; // list of WAV files
[XmlAttributeAtt ribute("TimeSta mp")]
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.942 5488-05:00">
<FileList>
<File xsi:type="xsd:s tring">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.942 5488-05:00">
<FileList>
<File xsi:type="xsd:s tring">C:\CD Data</File>
</FileList>
</Job>
</JobQueue>

Thanks in advance for any assistance.
Jon
Aug 17 '06 #1
1 5176
Rodders
1 New Member
Try:
public class SomeClass
{
[XmlArray("JobQu eue"), XmlArrayItem("J ob", 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
12630
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 object using Binary format but unable to do so using XML formatter. Is it possible to serialize an ArrayList object into XML? If somebody could pass on some sample code that would be really great. Thanks,
4
11373
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 should have worked fine since the class in question was already being serialized and deserialized as part of a Web service interface. What I found was that by deserializing from an XmlNodeReader instead of an XmlTextReader, XML Serialization doesn't work...
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 attributes, all share a base set of 4, one of the question types can have children with <option> elements, this is how the xml looks after serialization.... If you notice there is an extra <SelectionList> around the <option>'s in the final...
1
4614
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 project I work on uses Xml serialization to store game objects for loading. One of the techniques we use is to make an array property and use the set block to perform actions on the values after they're loaded from the xml, as in: public string Ids
0
1060
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(); ar.Add( new Role( "Admin" ) );
2
10047
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; using System.Xml.Serialization ; namespace MyAppl
5
8024
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 example of what I'd want to accomplish. Thanks Brad Example
3
2344
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 System.Collections.ArrayList type, but I'm unable to determine what to type into the Value feild for a default setting so the property will not be null at runtime...
0
1414
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 doesn't help. I still get:
0
8376
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
8290
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
8708
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
8489
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
8594
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
7307
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
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
5622
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
1916
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.