J
jamie
I've posted this in the XML forum and basically been told that it works for
them so I'm thinking this is A CF issue.
Basically I'm trying to serialize a class and the elements are coming back
out of order. Order is important in this case for me.
Here is my code
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.IO;
using System.Text;
namespace XML_test1
{
public partial class Form1 : Form
{
public Form1()
{
ArrayList temp = new ArrayList();
temp.Add("1");
BatchHeader test = new BatchHeader(temp);
InitializeComponent();
try
{
XmlSerializer x = new XmlSerializer(typeof(BatchHeader));
TextWriter writer = new StreamWriter("\\Program Files\\log scale manager
2\\" + "HBS.xml");
x.Serialize(writer, test);
MessageBox.Show("Done");
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
public class BatchHeader
{
public string ScaleSite;
public string FromScaleDate;
public string ToScaleDate;
public string SubmitterBatchID;
[System.Xml.Serialization.XmlElementAttribute(DataType = "integer")]
public string DocumentCount;
[System.Xml.Serialization.XmlElementAttribute(DataType = "integer")]
public string BatchControlTotal;
public BatchHeader(ArrayList batchLoads)
{
string[] BatchInfo;
ScaleSite = "First";
FromScaleDate = "Second";
ToScaleDate = "Third";
SubmitterBatchID = "fourth";
DocumentCount = "5";
BatchControlTotal = "6";
}
// default constructor needed for serializing
public BatchHeader()
{
}
}
}
And here is the result
<?xml version="1.0" encoding="utf-8"?>
<BatchHeader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SubmitterBatchID>fourth</SubmitterBatchID>
<DocumentCount>5</DocumentCount>
<BatchControlTotal>6</BatchControlTotal>
<ScaleSite>First</ScaleSite>
<FromScaleDate>Second</FromScaleDate>
<ToScaleDate>Third</ToScaleDate>
</BatchHeader>
This is all created in VS 2005, testing is being done on a Pocket PC
device. It's the same if I use the pocket pc 2003 emulator.
I would like it to come back
<ScaleSite>First</ScaleSite>
<FromScaleDate>Second</FromScaleDate>
<ToScaleDate>Third</ToScaleDate>
SubmitterBatchID>fourth</SubmitterBatchID>
<DocumentCount>5</DocumentCount>
<BatchControlTotal>6</BatchControlTotal>
but I can't figure out what is affecting the ordering in the results.
I have noticed that If I have a value of a space that becomes the first
element but I don't know if that's all the time or not.
Anyone have any ideas?
them so I'm thinking this is A CF issue.
Basically I'm trying to serialize a class and the elements are coming back
out of order. Order is important in this case for me.
Here is my code
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.IO;
using System.Text;
namespace XML_test1
{
public partial class Form1 : Form
{
public Form1()
{
ArrayList temp = new ArrayList();
temp.Add("1");
BatchHeader test = new BatchHeader(temp);
InitializeComponent();
try
{
XmlSerializer x = new XmlSerializer(typeof(BatchHeader));
TextWriter writer = new StreamWriter("\\Program Files\\log scale manager
2\\" + "HBS.xml");
x.Serialize(writer, test);
MessageBox.Show("Done");
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
public class BatchHeader
{
public string ScaleSite;
public string FromScaleDate;
public string ToScaleDate;
public string SubmitterBatchID;
[System.Xml.Serialization.XmlElementAttribute(DataType = "integer")]
public string DocumentCount;
[System.Xml.Serialization.XmlElementAttribute(DataType = "integer")]
public string BatchControlTotal;
public BatchHeader(ArrayList batchLoads)
{
string[] BatchInfo;
ScaleSite = "First";
FromScaleDate = "Second";
ToScaleDate = "Third";
SubmitterBatchID = "fourth";
DocumentCount = "5";
BatchControlTotal = "6";
}
// default constructor needed for serializing
public BatchHeader()
{
}
}
}
And here is the result
<?xml version="1.0" encoding="utf-8"?>
<BatchHeader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SubmitterBatchID>fourth</SubmitterBatchID>
<DocumentCount>5</DocumentCount>
<BatchControlTotal>6</BatchControlTotal>
<ScaleSite>First</ScaleSite>
<FromScaleDate>Second</FromScaleDate>
<ToScaleDate>Third</ToScaleDate>
</BatchHeader>
This is all created in VS 2005, testing is being done on a Pocket PC
device. It's the same if I use the pocket pc 2003 emulator.
I would like it to come back
<ScaleSite>First</ScaleSite>
<FromScaleDate>Second</FromScaleDate>
<ToScaleDate>Third</ToScaleDate>
SubmitterBatchID>fourth</SubmitterBatchID>
<DocumentCount>5</DocumentCount>
<BatchControlTotal>6</BatchControlTotal>
but I can't figure out what is affecting the ordering in the results.
I have noticed that If I have a value of a space that becomes the first
element but I don't know if that's all the time or not.
Anyone have any ideas?