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